hdu1217 Arbitrage
10.0 French francs, and 1 French franc buys 0.21 US dollar. Then, by converting currencies, a clever trader can start with 1 US dollar and buy 0.5 * 10.0 * 0.21 = 1.05 US dollars, making a profit of 5 percent.
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.
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.
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 2: No
#include<map>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
char s[100][100],s1[100],s2[100];
double dis[100][100];
int flag,n,index;
double max(double a,double b)
{
return a>b?a:b;
}
void floyd()
{
int i,j,k;
for(k=1;k<=index;k++){
for(i=1;i<=index;i++){
for(j=1;j<=index;j++){
dis[i][j]=max(dis[i][j],dis[i][k]*dis[k][j]);
}
}
}
for(i=1;i<=index;i++){
if(dis[i][i]>1){
flag=1;break;
}
}
return;
}
int main()
{
int m,i,j,num=0;
double a;
while(scanf("%d",&n)!=EOF && n!=0)
{
map<string,int> hash;
hash.clear();
memset(dis,0,sizeof(dis));
index=0;
for(i=1;i<=n;i++){
scanf("%s",s[i]);
if(hash[s[i]]==0){
index++;
hash[s[i]]=index;
}
}
flag=0;
scanf("%d",&m);
for(i=1;i<=m;i++){
scanf("%s%lf%s",s1,&a,s2);
if(strcmp(s1,s2)==0 && a>1)
flag=1;
if(dis[hash[s1]][hash[s2]]<a){
dis[hash[s1]][hash[s2]]=a;
}
}
printf("Case %d: ",++num);
//printf("%d\n\n",index);
if(flag==1){
printf("Yes\n");continue;
}
floyd();
if(flag)printf("Yes\n");
else printf("No\n");
}
return 0;
}
hdu1217 Arbitrage的更多相关文章
- HDU1217:Arbitrage(SPFA)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1217 题目大意 在每种钱币间进行各种交换,最后换回自己如果能赚,那么就Yes,否则No 注意应为有负权 ...
- DFS判断正环
hdu1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 【floyed】【HDU1217】【Arbitrage】
题目大意: 给你几种货币,以及几种汇率关系,问是否存在套利的可能? 思路: 初步想法:图上存在一个环的路径上权值相乘大于1.... 再者:该如何找到图上所有环呢.... 好吧 经过鸟神 和 况神的指点 ...
- Arbitrage HDU1217
汇率转换问题: 怎么样才能套利 可以用Floyd算法: #include<bits/stdc++.h> using namespace std; ][]; int main() { int ...
- 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
Time Limit: 1000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Java class name ...
- UVa 104 - Arbitrage(Floyd动态规划)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- Arbitrage(bellman_ford)
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16652 Accepted: 7004 Descri ...
- 最短路(Floyd_Warshall) POJ 2240 Arbitrage
题目传送门 /* 最短路:Floyd模板题 只要把+改为*就ok了,热闹后判断d[i][i]是否大于1 文件输入的ONLINE_JUDGE少写了个_,WA了N遍:) */ #include <c ...
随机推荐
- 计算机考研复试 A+B
题目描述 读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一位数字由对应的英文单词给出. 输入描述: 测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B ...
- FAT32、NTFS、exFAT有什么区别?
文件系统 我们经常会对电脑硬盘.U盘.移动硬盘进行格式化,而在格式化硬盘的时候会弹出文件系统的选项,分别有FAT32.NTFS.exFAT三种格式,那么FAT32.NTFS.exFAT有什么区别? 在 ...
- leetcode 31. Next Permutation (下一个排列,模拟,二分查找)
题目链接 31. Next Permutation 题意 给定一段排列,输出其升序相邻的下一段排列.比如[1,3,2]的下一段排列为[2,1,3]. 注意排列呈环形,即[3,2,1]的下一段排列为[1 ...
- DNS基础概要
dns服务系统由客户端和服务器组成,提供域名到ip地址的解析,或者提供ip地址到域名的逆向解析. 1.DNS域名空间 每个dns域名由分级的label构成,如www.sina.com.cn,由www. ...
- ABAP中SQL语句,指定索引(oracle)
①常用的两种方法: 1.指定使用全表扫描:%_HINTS ORACLE 'FULL(table_name)' 表示扫描整个表 2.指定索引:%_HINTS ORACLE 'INDEX("ta ...
- 算法模板 - C++ 高精度运算
C++算法板子 高精度 高精度推荐用python来写,python有大整数,这里写的是关于C++的高精度运算模板 1.高精 * 低精 #include <iostream> #includ ...
- 利用容器逃逸实现远程登录k8s集群节点
某天, 某鱼说要吃瞄, 于是...... 李国宝:边缘计算k8s集群SuperEdge初体验 zhuanlan.zhihu.com 图标 照着上一篇文章来说,我这边边缘计算集群有一堆节点. 每个节 ...
- SP338 ROADS
题目描述 城市中有R条有向马路,n个马路连接点,通过每条马路都要花去一定费用.你现在在编号为1的连接点 ,手里有k元钱,要去n号连接点的最短路径的长度是多少?途中经过道路的花费不能超过k.注意:两个 ...
- 带你走进memcache,老牌内存缓存技术
一.核心优化概述 什么是优化:以更小的资源支持更大负载网站的运行,以小博大. 思路:尽量减少用户等待时间,节省系统资源开销,节省带宽使用. 优化什么地方?有三方面:Memcache内存缓存技术.静态化 ...
- STM32驱动LCD实战
前段时间写了<STM32驱动LCD原理>和<STM32的FSMC外设简介>两篇文章,本文将对STM32驱动LCD进行实战应用.LCD是深圳市拓普微科技开发有限公司的LMT028 ...