# POJ 2240 && HDU 1217 Arbitrage（Floyd）

Description

Input

Output

Sample Input
3
USDollar
BritishPound
FrenchFranc
3
USDollar 0.5 BritishPound
BritishPound 10.0 FrenchFranc
FrenchFranc 0.21 USDollar

3
USDollar
BritishPound
FrenchFranc
6
USDollar 0.5 BritishPound
USDollar 4.9 FrenchFranc
BritishPound 10.0 FrenchFranc
BritishPound 1.99 USDollar
FrenchFranc 0.09 BritishPound
FrenchFranc 0.19 USDollar

0
Sample Output
Case 1: Yes
Case 2: No
Solution

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 111
int n,m;
double a[maxn][maxn];
char s[maxn][maxn];
int find(char *c)
{
for(int i=1;i<=n;i++)
if(strcmp(s[i],c)==0)return i;
}
int main()
{
int res=1;
while(~scanf("%d",&n),n)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[i][j]=i==j?1:0;
for(int i=1;i<=n;i++)scanf("%s",s[i]);
scanf("%d",&m);
char x[maxn],y[maxn];
double temp;
while(m--)
{
scanf("%s%lf%s",x,&temp,y);
int u=find(x),v=find(y);
a[u][v]=temp;
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[i][j]=max(a[i][j],a[i][k]*a[k][j]);
int flag=0;
for(int i=1;i<=n;i++)
if(a[i][i]>1.0)
{
flag=1;
break;
}
printf("Case %d: %s\n",res++,flag?"Yes":"No");
}
return 0;
}


#### poj-2240-Arbitrage（Bellman-ford算法练习 + Floyd算法练习）

2016-08-08 20:38:22

#### 杭电 ACM HDU 1217 Arbitrage（最短路 floyd算法）

2015-06-11 14:01:32

#### HDU1217:Arbitrage(SPFA)

2013-11-25 22:35:08

#### POJ 2240 Arbitrage(最短路 套汇)

2014-10-29 10:17:53

#### HDOJ-1217-Arbitrage 解题报告

2014-06-19 14:48:53

#### poj2240 Arbitrage (spfa判环)

2016-03-20 18:42:15

#### hdu 1217/poj 2240 Arbitrage【floyd】

2016-05-04 16:27:54

#### HDU 1217 and POJ 2240 Arbitrage

2015-09-02 11:50:12

#### POJ 2240 HDU 1217 Arbitrage

2014-06-28 13:55:29

#### hdu 1217 && poj2240 Arbitrage 最短路

2014-02-15 19:57:30