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<iomanip> using namespace std; double map[110][110]; int mark[110]; int main() { int n,m; while(1) { scanf("%d",&n); //cout<<n<<endl; if(!n) break; scanf("%d",&m); //cout<<m<<endl; memset(map,0,sizeof(map)); memset(mark,0,sizeof(mark)); int a,b; double p; for(int i=0;i<m;i++) { scanf("%d%d%lf",&a,&b,&p); //cin>>p; //cout<<a<<b<<p<<endl; p/=100; map[a][b]=p; map[b][a]=p; } int s=1; double po=1; while(s!=n) { int min=-1; int minI; for(int i=1;i<=n;i++) { if(!mark[i]&&map[s][i]) { if(map[s][i]>min) { minI=i; } } } mark[minI]=1; po*=map[s][minI]; s=minI; } cout<<fixed<<setprecision(6)<<po*100<<" percent"<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator