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 |
给我几组错的测试数据也行啊#include<iostream> #include<math.h> using namespace std; const int N = 101; const long infinit = 4000000; typedef struct Money { long P; int L,X; }Money; Money money[N]; bool ttry(int path[],int w,int n,int m) { int t; while(w > 0) { t = abs(money[w].L-money[n].L); if (t>m) { return false; } w = path[w]; } return true; } int main() { long G[N][N]; int i,j,m,n,t1,t2,min,w,h; int mark[N],d[N],path[N]; while(cin >> m >> n) { for ( i = 1; i <= n ; i++) { path[i] = 1; d[i] = infinit; mark[i] = 0; } path[1] = 0; for ( i = 1; i <= n; i++) for (j = 1; j<= n; j++) { G[i][j] = infinit; if (i==j) { G[i][j] = 0; } } for (i = 1; i <= n; i++) { cin >> money[i].P; cin >> money[i].L; cin >> money[i].X; for (j = 1; j<= money[i].X;j++) { cin >> t1; cin >> t2; G[i][t1] = t2; //G[t1][i] = t2; } } for (i = 1;i <= n; i++) if (G[1][i]!=infinit&&ttry(path,1,i,m)==true) { d[i] = G[1][i]+money[i].P; } mark[1] = 1; for (i = 2; i <= n; i++) { min = infinit; w = 1; for (j = 2; j <= n; j++) if (mark[j]==0&&min>d[j]) { min = d[j]; w = j; } mark[w] = 1; for (j = 1; j <= n; j++) if(ttry(path,w,j,m)==true) if (mark[j]==0&&G[w][j]<infinit&&(d[j]>d[w]-money[w].P+G[w][j]+money[j].P)) { d[j] = d[w]-money[w].P+G[w][j]+money[j].P; path[j] = w; } } for(i = 2; i <= n; i++) if (d[i]<d[1]) { d[1] = d[i]; } cout << d[1] ; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator