先写主体结构,后填充,如果是主体结构错了,是很难发现的
二维数组的fill填充
1 #include2 #include 3 #include 4 using namespace std; 5 const int Maxv = 510; 6 const int INF = 0x3fffffff; 7 int Cmax, N, Sp, M; 8 int perfect; 9 vector pre[Maxv]; 10 bool vis[Maxv]= { false}; 11 int dis[Maxv]; 12 int bikes[Maxv]; 13 int Mgraph[Maxv][Maxv]; 14 vector tmppath; 15 vector path; 16 int minneed=INF, minremain=INF; 17 void dijkstra(int s) 18 { 19 fill(dis,dis+Maxv,INF); 20 dis[s]=0; 21 for(int i=0; i<=N; i++) 22 { 23 int u=-1, MIN=INF; 24 for(int j=0; j<=N; j++) 25 { 26 if(dis[j] =0; i--) 65 { 66 int id=tmppath[i]; 67 if(bikes[id]>0) 68 { 69 remain+=bikes[id]; 70 } 71 else if(bikes[id]<0) 72 { 73 if(remain>=abs(bikes[id])) 74 { 75 remain+=bikes[id]; 76 } 77 else 78 { 79 need+=abs(bikes[id])-remain; 80 remain=0;; 81 82 } 83 } 84 } 85 86 if(need =0;i--){137 printf("%d",path[i]);138 if(i!=0)printf("->");139 }140 printf(" %d",minremain);141 142 return 0;143 }