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< ...
随机推荐
- Android项目实战--手机卫士18--读取用户的短信内容以及短信备份
我们今天要说的就是我们手机卫士里面的高级工具里面的短信备份功能啦,其实这个软件备份的功能也很简单,就是把用户的短信读出来,然后写到一个xml或者数据库里面, 但我们这里的是读取到xml里面的. 首先我 ...
- *candy——leetcode
/* */ #include<iostream> #include<vector> //#include<algorithm> #include <windo ...
- Java经典23种设计模式之结构型模式(一)
结构型模式包含7种:适配器模式.桥接模式.组合模式.装饰模式.外观模式.享元模式.代理模式. 本文主要介绍适配器模式和桥接模式. 一.适配器模式(Adapter) 适配器模式事实上非常easy.就像手 ...
- hdu1074 Doing Homework(状态压缩DP Y=Y)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- .NET简单的语句
获取当前时间的代码: Response.Write(DateTime.Now); 第一次加载页面的语句: if (!IsPostBack) { Response.Write("这是第一次加载 ...
- LSI SAS 3108 配置操作
配置LSISAS3108 介绍LSISAS3108的配置操作. 5.1 登录CU界面 介绍登录LSISAS3108的CU配置界面的方法,以及CU界面的主要功能. 5.2 创建RAID 介绍在LSISA ...
- 关于ASP.Net 4.0的ClientID
我们知道因为在原来的ASP.NET应用程序中使用服务端控件在生成ClientID的时,是很难控制的,特别是在嵌套的控件的时候,比如在多个嵌套Repeater中要控制某一个控件生成的html的ID属性, ...
- Android学习手记(6) TabActivity和TabHost
使用TabHost可以实现标签式效果,将两个Activity放在两个Tab内. 首先,需要基于MainActivity创建一个TabHost对象. TabHost tabHost = this.get ...
- Centos 5.2安装配置DNS服务器
BIND安装配置(主从)我的系统环境:centos 5.2 作者:哈密瓜 主:我采用的是yum安装[root@linux src]#yum -y install bind* 生成rndc控制命令的ke ...
- 软件测试 homework2
1. 程序1: for循环的i>0改为i>=0: 程序2: for循环for (int i = 0; i < x.length; i++)改为for (int i = x.l ...