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

找不到WA的原因, 哪位帮帮忙看下吧!

Posted by 417370112 at 2006-11-07 12:21:13 on Problem 2240
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string.h>
#define SIZE 31
#define NAME_SIZE 100 

using namespace std;

int n, m;
char name[SIZE][NAME_SIZE];
double edge[SIZE][SIZE];
// bool con = false;

double max ( double x, double y )
{
       return (x > y ? x : y);
}
void initial ()
{
     int i, j;
     for (i = 0; i < n; i ++)
     {
         edge[i][i] = 1.0;
         for (j = i + 1; j < n; j ++)
         {
             edge[i][j] = edge[j][i] = 0;
         }
     }
}
bool floyd ()
{
     int i, j, k;
     for (k = 0; k < n; k ++)
     {
         for (i = 0; i < n; i ++)
         for (j = 0; j < n; j ++)
         {
             edge[i][j] = max (edge[i][j], edge[i][k] * edge[k][j]);
         }
         
         for (i = 0; i < n; i ++)
         {
             if (edge[i][i] > 1.0)
             {
                            return true;
             }
         }

     }
     return false;
}
int main ()
{
    #ifndef ONLINE_JUDGE
    freopen ("Arbitrage.txt", "r", stdin);
    #endif
    int i, j, x, y, c;
    double vir;
    char str1[NAME_SIZE], str2[NAME_SIZE];
    c = 1;
    while (cin >> n && n)
    {
          printf ("Case %d: ", c);
          for (i = 0; i < n; i ++)
          {
              cin >> name[i];
          }
          initial ();
          cin >> m;
          for (i = 0; i < m; i ++)
          {
              cin >> str1 >> vir >> str2;
              for (j = 0; j < n; j ++)
              {
                  if ( !strcmp (str1, name[j]) )
                  {
                       x = j;
                  }
                  else if ( !strcmp (str2, name[j]) )
                  {
                       y = j;
                  }
              }
              edge[x][y] = vir;
          }
          if ( floyd () )
          {
               printf ("Yes\n");
          }
          else
          {
              printf ("No\n");
          }
          c ++;
    }
    
 
    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