标签:style gre max lin sans text star pop imp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5679 Accepted Submission(s): 2630
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
Case 1: Yes Case 2: No
比方1美元能够买0.5英镑。而1英镑能够买10法郎,1法郎能够买0.21美元那么可用通过套汇使用1美元买到1.05美元,套利是存在的。以下给出各个货币的种类和名称,再给出一些货币兑换的汇率。请问是否存在套利?
<span style="font-size:12px;">#include<cstdio> #include<cstring> #define maxn 32 double map[maxn][maxn]; int n,t; void floyd() { int i,j,k; for(k=0;k<n;++k) { for(i=0;i<n;++i) { for(j=0;j<n;++j) { if(map[i][j]<map[i][k]*map[k][j]) map[i][j]=map[i][k]*map[k][j]; } } } int sign=0; for(i=0;i<n;++i) { if(map[i][i]>1)//自身的汇率为1。若汇率大于1则说明能套汇 { sign=1; break; } } if(sign) printf("Yes\n"); else printf("No\n"); } int main() { int m,i,j,a,b,t=1;; double c; char str[32][32],s1[32],s2[32]; while(scanf("%d",&n)&&n) { for(i=0;i<n;++i) { for(j=0;j<n;++j) map[i][j]=0; } for(i=0;i<n;++i) scanf("%s",str[i]); scanf("%d",&m); while(m--) { scanf("%s%lf%s",s1,&c,s2); for(i=0;i<n;++i) { if(strcmp(s1,str[i])==0) a=i; if(strcmp(s2,str[i])==0) b=i; } map[a][b]=c; } printf("Case %d: ",t++); floyd(); } return 0; }</span>
HDOJ 1217 Arbitrage(拟最短路,floyd算法)
标签:style gre max lin sans text star pop imp
原文地址:http://www.cnblogs.com/yxysuanfa/p/7190468.html