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 |
G++过不了,C++就过了,这什么原因啊#include<string.h> #include<stdio.h> #include<algorithm> #include<iostream> #include<queue> #define INF 0 #define N 20000+10 #define M 100+10 using namespace std; typedef struct { int to; double w; int next; }node; node E[N]; int head[M],cnt; int n,m; double dis[M]; void ADD(int a,int b,double w) { E[++cnt].to=b; E[cnt].w=w; E[cnt].next=head[a]; head[a]=cnt; } double spfa(int s,int t) { for(int i=0;i<M;i++) dis[i]=INF; dis[s]=1; int visit[M]={0}; queue<int>Q; Q.push(s); while(!Q.empty()) { int k=Q.front(); Q.pop(); visit[k]=0; for(int i=head[k];i;i=E[i].next) { int to=E[i].to; double w=E[i].w; if(dis[k]*w>dis[to]) { dis[to]=dis[k]*w; if(!visit[to]) { visit[to]=1; Q.push(to); } } } } return dis[t]; } int main() { int a,b; double c; while(~scanf("%d",&n)) { if(n==0) break; memset(head,0,sizeof(head)); cnt=1; scanf("%d",&m); for(int i=0;i<m;i++) { scanf("%d%d%lf",&a,&b,&c); c=c/100; ADD(a,b,c); ADD(b,a,c); } double step=spfa(1,n); printf("%.6lf percent\n",step*100); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator