Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
题意理解的问题?? AC了 但不明白题目说一个人和一个与他等级较低的一个人交易了,就不能再和等级比他高的人进行交易了 我AC的代码,只要求所有交易的(i,i+m)的范围内即可, 没有判断上面的说法。 难道我理解错了?? //poj 1062 #include<iostream> #include<stdio.h> #include<cctype> #include<queue> #include<vector> #include<string> #include<cstring> using namespace std; const int MAX = 110; const int INF = 0x0fffffff; int M, N; int map[MAX][MAX]; bool f[MAX][MAX]; int price[MAX], dengji[MAX]; int d[MAX]; bool v[MAX]; void dijstra(int m, int n) { //cout<<m<<' '<<n<<endl; memset(v, 0, sizeof v); for(int i = 1; i <= N; i++) d[i] = INF; d[1] = price[1]; for(int i = 1; i<= N; i++ ) { int min = INF, index = 0; for(int j=1; j<=N; j++) if(v[j] == false && dengji[j] >= m && dengji[j] <= n && d[j] < min) { min = d[j]; index = j; } if( min == INF)break; v[index] = true; for(int j = 1; j <= N; j++) { if(dengji[j] <= n && dengji[j] >= m &&f[index][j]&& d[j] > d[index] +map[index][j] + price[j] - price[index] ) d[j] = d[index] +map[index][j] + price[j] - price[index] ; } } // for(int i=1; i<= N; i++) // cout<<d[i]<<' '; // cout<<endl; } int main() { cin >> M >> N; memset (map , 0, sizeof map); memset( f, 0, sizeof f); int X; for(int i=1; i <= N; i++) { cin >> price[i] >> dengji[i] >> X; for(int j = 1 ,t, p ; j <= X; j++) { cin >> t >> p; map[i][t] = p; f[i][t] = true; } } int ans=INF; for(int i = dengji[1]-M ; i <= dengji[1]; i++) { dijstra(i, i+M); for(int j = 1; j <= N; j++ ) { if( d[j] != INF && d[j] < ans) ans = d[j]; } } cout << ans << endl; system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator