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 |
高手帮忙看下 3Q了#include<iostream> using namespace std; #include<algorithm> int w[22][22]; int len[22]; bool s[22]; int b[22]; const int max1=999999999; int main() { int time; int x; for(int m=0;m<22;m++) for(int n=0;n<22;n++) w[m][n]=max1; time=0; while(cin>>b[1]) { time++; int sum=0; cout<<"Test Set #"<<time<<endl; for(int i=1;i<=b[1];i++) { cin>>x; w[1][x]=1; w[x][1]=1; } for(int i=2;i<=19;i++) { cin>>b[i]; sum+=b[i]; for(int j=1;j<=b[i];j++) { cin>>x; w[i][x]=1; w[x][i]=1; } } int case1; cin>>case1; int begin,end; int begin1,end1; for(int i=0;i<case1;i++) { cin>>begin>>end; begin1=begin; end1=end; if(begin>end) swap(begin,end); for(int i=1;i<=20;i++) { len[i]=w[begin][i]; s[i]=0; } s[begin]=1; len[begin]=0; for(int m=0;m<19;m++) { int min1=max1; int u; for(int n=1;n<=20;n++) { if(s[n]==0&&s[m]<min1) { min1=s[m]; u=n; } } s[u]=1; int w1; for(int k=1;k<=20;k++) { w1=w[k][u]; if(s[k]==0&&w1<max1&&w1+len[u]<len[k]) { len[k]=w1+len[u]; } } } // for(int xx=1;xx<=20;xx++) // cout<<len[xx]<<" "<<endl; // cout<<begin<<" to "<<end; cout<<begin1<<" to "<<end1<<": "<<len[end]<<endl; //cout<<" "<<len[end]<<endl; } cout<<endl; } system("pause"); return 0; } 过了数据 可以WR ;我使用DIJKSTRA的想法做得 为什么不行?? 谢谢了 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator