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

各位大哥哥,大姐姐,帮忙看看吧!!!!

Posted by 0394 at 2010-08-23 21:39:20 on Problem 2240 and last updated at 2010-08-24 21:21:42
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

char ch[31][20];
double moneoy[31];
int n,m;
typedef struct
{
    double r;
    int x,y;
}node;
node e[1000];

int serv(char s[20])
{
    int i;
    for(i=1;i<=n;i++)
        if(strcmp(ch[i],s)==0)
            return i;
}

int bellman()
{
    int i,k;
        for(i=1;i<=n;i++)
            moneoy[i]=1;
        for(k=1;k<n;k++);
        {
            for(i=0;i<m;i++)
               if(moneoy[e[i].y]<moneoy[e[i].x]*e[i].r)
                    moneoy[e[i].y]=moneoy[e[i].x]*e[i].r;
        }
        for(i=0;i<m;i++)
            if(moneoy[e[i].y]<moneoy[e[i].x]*e[i].r)
                return 1;
    return 0;
}
int main()
{
    int i,k=1,flag;
    double rat;
    char a[20],b[20];
    while(scanf("%d",&n)!=EOF&&n)
    {
        for(i=1;i<=n;i++)
            scanf("%s",ch[i]);
        scanf("%d",&m);
        for(i=0;i<m;i++)
        {
            scanf("%s%lf%s",a,&rat,b);
            e[i].x=serv(a);
            e[i].y=serv(b);
            e[i].r=rat;
        }
        flag=bellman();
        if(flag)
            printf("Case %d: Yes\n",k++);
        else
            printf("Case %d: No\n",k++);
    }
    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