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 |
各位牛人看一下,问什么测试数据都通过了,还是wa,万分感谢!#include <iostream> using namespace std; typedef struct { int id; int price; }tidai; typedef struct { int price; int position; int tidai_num; tidai *tidais; }good; typedef int* IntArrayPtr; int main() { int position_gap,num; while(cin>>position_gap>>num) { good *goods = new good[num+1]; IntArrayPtr *cell = new IntArrayPtr[num+1]; for(int u = 0;u<num+1;u++) { cell[u] = new int[num+1]; } int *d = new int[num+1]; int *position = new int[num+1]; bool *final = new bool[num+1]; for(int o=1;o<num+1;o++) { for(int z=1;z<num+1;z++) { cell[o][z] = -1; } } for(int l=1;l<num+1;l++) { cin>>goods[l].price>>goods[l].position>>goods[l].tidai_num; goods[l].tidais = new tidai[goods[l].tidai_num]; cell[l][l] = goods[l].price; for(int s=0;s<goods[l].tidai_num;s++) //tidais的下标从0开始 { cin>>goods[l].tidais[s].id>>goods[l].tidais[s].price; } } for(int f=1;f<num+1;f++) { for(int r=0;r<goods[f].tidai_num;r++) { cell[f][goods[f].tidais[r].id] = goods[f].tidais[r].price; } } int origin_max = 0; for(int v=1;v<num+1;v++) { for(int w=1;w<num+1;w++) { if(cell[v][w]>origin_max) { origin_max = cell[v][w]; } } } for(int aa=1;aa<num+1;aa++) { for(int bb=1;bb<num+1;bb++) { if(cell[aa][bb]==-1) { cell[aa][bb] = origin_max+1; } } } int qu_position = goods[1].position; IntArrayPtr *copy = new IntArrayPtr[num+1]; for(int z = 0;z<num+1;z++) { copy[z] = new int[num+1]; } int *M = new int[position_gap+1]; for(int w=0;w<position_gap+1;w++) { M[w] = cell[1][1]; for(int c=1;c<num+1;c++) { for(int v=1;v<num+1;v++) { copy[c][v] = cell[c][v]; //cout<<copy[c][v]<<" "; } //cout<<endl; } for(int f=2;f<num+1;f++) { if((goods[f].position<qu_position-position_gap+w)|| (goods[f].position>qu_position+w)) { for(int r=1;r<num+1;r++) { copy[r][f] = origin_max+1; copy[f][r] = origin_max+1; } } } for(int q=1;q<num+1;q++) { d[q] = copy[1][q]; final[q] = false; } int n =1; final[1] = true; for(int p =1;p<num;p++) { int min = origin_max+1; for(int m=1;m<num+1;m++) { if(!final[m] || m == n) if(d[m]<min) { min = d[m]; n = m; } } if(final[n]) { M[w] = d[n]; break; } else final[n] = true; for(int a = 1;a<num+1;a++) { if(!final[a]) { if(d[n]+copy[n][a]<d[a]) { d[a] = d[n] + copy[n][a]; } } } d[n] = d[n] + copy[n][n]; } if(d[num]<M[w]) M[w] = d[num]; } int min_price = origin_max+1; for(int t=0;t<position_gap+1;t++) { if(M[t]<min_price) min_price = M[t]; } cout<<min_price<<endl; for(int y = 0;y<num+1;y++) { delete []cell[y]; delete []copy[y]; if(y!=0) { delete []goods[y].tidais; } } delete []cell; delete []d; delete []position; delete []final; delete []goods; delete []copy; delete []M; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator