POJ-2240
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 19063 | Accepted: 8069 |
Description
Your job is to write a program that takes a list of currency
exchange rates as input and then determines whether arbitrage is
possible or not.
Input
input will contain one or more test cases. Om the first line of each
test case there is an integer n (1<=n<=30), representing the
number of different currencies. The next n lines each contain the name
of one currency. Within a name no spaces will appear. The next line
contains one integer m, representing the length of the table to follow.
The last m lines each contain the name ci of a source currency, a real
number rij which represents the exchange rate from ci to cj and a name
cj of the destination currency. Exchanges which do not appear in the
table are impossible.
Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n.
Output
each test case, print one line telling whether arbitrage is possible or
not in the format "Case case: Yes" respectively "Case case: No".
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
思路:
抽象出来这题就是要求一个图的最大环,仍然用Floyd算法
要注意下G数组的对角线的值都要是1
#include <iostream>
#include <cstring>
#include <map>
using namespace std; map<string,int> money;
double G[][];
int n,m; void Floyd()
{
for(int k = ;k <= n;k++)
for(int i = ;i <= n;i++)
for(int j = ;j <= n;j++)
if(G[i][j] < G[i][k]*G[k][j])
G[i][j] = G[i][k]*G[k][j];
} int main()
{
int countt = ;
while(cin>>n && n)
{
string tmp;
for(int i = ;i <= n;i++)
{
cin>>tmp;
money.insert(make_pair(tmp,i));
G[i][i] = ;
}
cin>>m;
string t1,t2;
double t;
for(int i = ;i <= m;i++)
{
cin>>t1>>t>>t2;
G[money[t1]][money[t2]] = t;
}
Floyd();
int flag = ;
for(int i = ;i <= n;i++)
if(G[i][i] > ) {
flag = ;
break;
}
if(flag)
cout<<"Case "<<++countt<<": Yes"<<endl;
else
cout<<"Case "<<++countt<<": No"<<endl;
}
return ;
}
POJ-2240的更多相关文章
- 最短路(Floyd_Warshall) POJ 2240 Arbitrage
题目传送门 /* 最短路:Floyd模板题 只要把+改为*就ok了,热闹后判断d[i][i]是否大于1 文件输入的ONLINE_JUDGE少写了个_,WA了N遍:) */ #include <c ...
- poj 2240 Arbitrage (Floyd)
链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- poj 2240 Arbitrage 题解
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21300 Accepted: 9079 Descri ...
- poj 2240(floyd)
http://poj.org/problem?id=2240 题意:有些人会利用货币的不用汇率来进行套现,比如1美元换0.5英镑,而1英镑又可以换10法郎,而1法郎又可以换0.21的美元,那么经过货币 ...
- POJ 2240 && ZOJ 1082 Arbitrage 最短路,c++ stl pass g++ tle 难度:0
http://poj.org/problem?id=2240 用log化乘法为加法找正圈 c++ 110ms,g++tle #include <string> #include <m ...
- POJ 2240 Arbitrage(floyd)
http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...
- poj 2240 Arbitrage (最短路 bellman_ford)
题目:http://poj.org/problem?id=2240 题意:给定n个货币名称,给m个货币之间的汇率,求会不会增加 和1860差不多,求有没有正环 刚开始没对,不知道为什么用 double ...
- POJ 2240 Arbitrage【Bellman_ford坑】
链接: http://poj.org/problem?id=2240 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- POJ 2240 Arbitrage(判正环)
http://poj.org/problem?id=2240 题意:货币兑换,判断最否是否能获利. 思路:又是货币兑换题,Belloman-ford和floyd算法都可以的. #include< ...
随机推荐
- java中基于TaskEngine类封装实现定时任务
主要包括如下几个类: 文章标题:java中基于TaskEngine类封装实现定时任务 文章地址: http://blog.csdn.net/5iasp/article/details/10950529 ...
- Apache http强制转为https页面访问(转)
1 在httpd.conf文件里使下面模块生效 LoadModule rewrite_module modules/mod_rewrite.so 2 httpd.conf配置文件或者是在httpd ...
- JAVA实现AES和MD5加密
package test; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; ...
- [转] 为什么医疗咨询服务公司Evolent Health仅用4年就华丽上市?
让医疗主体,即医院和医生担任保险角色,完全控制保费,实现医疗机构的利益最大化.美国公司EvolentHealth帮助所有医院实现这一梦想. 不觉间,已步入2015的下半年.当国内还在讨论商业保险何时能 ...
- DBMS_STATS常用方法(收集oracle信息)
–收集数据库信息EXEC DBMS_STATS.gather_database_stats;EXEC DBMS_STATS.gather_database_stats(estimate_percent ...
- (转)使用DataTime这个类来获取当前的时间
我们可以通过使用DataTime这个类来获取当前的时间.通过调用类中的各种方法我们可以获取不同的时间:如:日期(--).时间(::).日期+时间(-- ::)等. //获取日期+时间 DateTime ...
- 9、第九节课jquery选择器jq2,20151007
1.表单选择器 2.not 里面不能加其他标签 $div p:not(not:disable) 错误的 $div p:not(:disable) 正确的 3.选择设置相应属性的标签项 $(&quo ...
- JAVA彩色图片变灰处理
File file = new File("F:/firefox.png"); File destFile = new File("F:/pic/" + Sys ...
- Navicat:cant create OCI environment.
一直在使用 Navicat ,这是一个数据库客户端软件,能连接多种不同类型的数据库,给我们的日常的工作带来了不少的便捷. 最近,我在电脑上安装了oracle的客户端ODTwihtODAC121012, ...
- Activity的学习
安卓的四大组件分别是 Activity ,Service服务, BroadcastReceiver广播接收器,ContentProvide内容提供器 . Activity: Activity是应用程序 ...