Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

G++过不了,C++就过了,这什么原因啊

Posted by letterwuyu at 2014-10-05 15:31:44 on Problem 2472
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator