Arbitrage
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
Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n.
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
最短路,一直很纠结,一直搞不懂,第一次自己A最短路,看着模板敲啊
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
struct node
{
int a,b;
double v;
} g[];//储存钱之间的汇率
int main()
{
int m,n,i,j,num=;
double v,dis[];
char money[],moneyt[];//谁让钱是字符串呢
while(cin>>n&&n)
{
num++,n++;
map<string,int>mapp;//为了方便把钱编号,用数组可以模拟,太麻烦
map<string,int>::iterator iter;//声明迭代器
for(i=; i<n; i++)
{
cin>>money;
mapp.insert(pair<string,int>(money,i));//插入钱和序号,相当于编号
}
cin>>m;
for(i=; i<m; i++)
{
scanf("%s %lf %s",money,&v,moneyt);//输入兑换比例
iter=mapp.find(money);//查找对应序号
g[i].a=iter->second;
g[i].v=v;
iter=mapp.find(moneyt);//查找对应序号
g[i].b=iter->second;
}
memset(dis,,sizeof(dis));//标记数组置零
dis[]=;
for(i=; i<n; i++)//n-1次松弛
for(j=; j<m; j++)
if(dis[g[j].b]<dis[g[j].a]*g[j].v)
dis[g[j].b]=dis[g[j].a]*g[j].v;
int flag=;
for(j=; j<m; j++)//还可以继续变大,就说明可以赚钱啊
if(dis[g[j].b]<dis[g[j].a]*g[j].v)
flag=;
printf("Case %d: ",num);
if(flag)
printf("Yes\n");
else
printf("No\n");
}
return ;
}
Arbitrage的更多相关文章
- 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 ...
- poj-------(2240)Arbitrage(最短路)
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15640 Accepted: 6563 Descri ...
- ZOJ 1092 Arbitrage
原题链接 题目大意:Arbitrage这个单词的解释是“套利交易”,就是利用几个币种之间的汇率差价来赚钱.比如人民币兑美元6:1,美元兑欧元1.5:1,欧元兑人民币10:1,那么用9元人民币可以换1. ...
- poj 2240 Arbitrage bellman-ford算法
点击打开链接 Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13434 Accepted: 5657 ...
- HDU 1217 Arbitrage (Floyd)
Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...
- POJ 2240 Arbitrage (求负环)
Arbitrage 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/I Description Arbitrage is the ...
- POJ2240——Arbitrage(Floyd算法变形)
Arbitrage DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform o ...
随机推荐
- Linux系统的Cache工作原理和管理机制
Linux系统Cache 管理是 Linux 内核中一个很重要并且较难理解的组成部分.本文详细介绍了 Linux 内核中文件 Cache 管理的各个方面,希望能够帮助到你. 操作系统和文件 Cache ...
- myNote
源码地址 :http://450640526.ys168.com/ 编辑器是WEBBWOSER制作的 你的Internet Explorer的版本至少要是8.0的否则用不了 还有很多BUG 很多功能没 ...
- C# 该行已经属于还有一个表 的解决方法
产生错误的代码: DataTable dtContract_src = Oper.GetDataTable("select * from T_Contract where ProjectID ...
- 廖雪锋笔记1---python变量类型
整型:a/b a//b a%b 浮点型:.2 字符串: "" '' r"" r'' '''...''' r'''...'''' 变量值共享:写时复制 NULL型 ...
- mac tips
1. Mac Terminal color for different types 在 ~ 先建立一个文件 ~/.bash_profile 加入下面的两行:export CLICOLOR=1expo ...
- Servlet 过滤器
一.过滤器介绍 在Servlet 2.3中定义了过滤器,它能够对Servlet容器的请求和响应进行检查和修改. Servlet过滤器能够在Servlet被调用之前检查Request对象,并修改Requ ...
- iOS 数据持久化(3):Core Data
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...
- Writing Your First Test
Let's say you have an activity layout that represents a welcome screen: <?xml version="1.0&q ...
- mac skim 修改背景色
defaults write -app skim SKPageBackgroundColor -array 0.78 0.93 0.80 1
- 树形dp练习
/*poj 1463 最小点覆盖 匈牙利*/ #include<iostream> #include<cstdio> #include<cstring> #defi ...