poj 2240 Arbitrage
Time Limit: 1000 MS Memory Limit: 65536 KB
64-bit integer IO format: %I64d , %I64u Java class name: Main
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
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
题意:对于每一个顶点构成的回路 兑换率是否大于1
#include <iostream>
#include <string.h>
#include <stdio.h> using namespace std;
#define maxx 35
#define maxn 1000
char name[maxx][],a[],b[]; ///链表进行存储
double maxdis[maxn]; ///类似于dis[]数组 不过这次求最大回路
double x; ///兑换率
int n,t;
int falg; struct exchange
{
int ci,cj;
double cij;
}ex[maxn]; void Bellman(int v0)
{
falg=;
memset(maxdis,,sizeof(maxdis));
maxdis[v0]=;
for(int k=;k<=n;k++) ///要寻找回路 所以从maxdis[0]递推maxdis[1]....maxdis[n]
{
for(int i=;i<t;i++) ///每条边加入是否值变大使最大
{
if(maxdis[ex[i].ci]*ex[i].cij>maxdis[ex[i].cj]) ///是程的关系了~~~
{
maxdis[ex[i].cj]=maxdis[ex[i].ci]*ex[i].cij; ///求最大的 遇到大的就更新
}
}
}
if(maxdis[v0]>)
falg=;
} int main()
{
int num;
int casee=;
while(scanf("%d",&n),n)
{
for(int i=;i<n;i++)
{
cin>>name[i];
//scanf("%s",name[num]);
}
int i,j,k;
scanf("%d",&t);
for(i=;i<t;i++)
{
cin>>a>>x>>b;
//scanf("%s%if%s",a,&x,b);
for(j=;strcmp(a,name[j]);j++); ///,是空循环 没有循环语句的意思
for(k=;strcmp(b,name[k]);k++); ///将字符串变成了数字 对应关系
ex[i].ci=j;
ex[i].cij=x;
ex[i].cj=k;
///cout<<i<<' '<<j<<' '<<k<<"!!!!!!!"<<endl; 输出一次啊 挺神奇的东东
}
for(int i=;i<n;i++)
{
Bellman(i); ///遍历每一个点的回路
if(falg) ///如果出现兑换率〉1的现象 标记直接退出就好
break;
}
if(falg)
printf("Case %d: Yes\n",++casee);
else
printf("Case %d: No\n",++casee);
}
return ;
}
poj 2240 Arbitrage的更多相关文章
- 最短路(Floyd_Warshall) POJ 2240 Arbitrage
题目传送门 /* 最短路:Floyd模板题 只要把+改为*就ok了,热闹后判断d[i][i]是否大于1 文件输入的ONLINE_JUDGE少写了个_,WA了N遍:) */ #include <c ...
- 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 Arbitrage (Floyd)
链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...
- 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(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(判正环)
http://poj.org/problem?id=2240 题意:货币兑换,判断最否是否能获利. 思路:又是货币兑换题,Belloman-ford和floyd算法都可以的. #include< ...
- poj 2240 Arbitrage(Bellman_ford变形)
题目链接:http://poj.org/problem?id=2240 题目就是要通过还钱涨自己的本钱最后还能换回到自己原来的钱种. 就是判一下有没有负环那么就直接用bellman_ford来判断有没 ...
随机推荐
- .net实现调用本地exe等应用程序的办法总结
根据客户需求用户要实现在一个BS系统上打开本地的一应用程序,在网上查了好多资料再加上自己的各种测试,到最后功能是实现了,只不过还存在一些问题,接下来会先把各种方法一一列举出来 1.先写最终测试通过的这 ...
- 【Tree 2】树形结构数据呈现的非递归算法(循环)实现
一.基本概况 上一篇博客介绍到用递归实现树结构数据的查找,那么这篇博客,我就结合自己对于树的理解,然后用一种非递归的方式进行树结构数据的处理.首先,改造数据库表设计,加入度的概念: 首先,layer的 ...
- 通过 ES6 Promise 和 jQuery Deferred 的异同学习 Promise
Deferred 和 Promise ES6 和 jQuery 都有 Deffered 和 Promise,但是略有不同.不过它们的作用可以简单的用两句话来描述 Deffered 触发 resolve ...
- 移动手机专题rem布局实践+主要代码
HTML开头部分 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" / ...
- Maven实战(四)生命周期
1. 三套生命周期 Maven拥有三套相互独立的生命周期,它们分别为clean,default和site. 每个生命周期包含一些阶段,这些阶段是有顺序的,并且后面的阶段依赖于前面的阶段,用户和 ...
- android自定义进度圆与定时任务
先看代码:自定进度圆 public class ProgressCircle extends View { private Paint paint; private int strokewidth = ...
- UVa 10071 - Back to High School Physics
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=s ...
- Python 集合方法总结
1.添加一个元素: add(...) Addan element to a set. 1 2 3 4 >>> a = {'shaw',11,22} >>>a. ...
- QT报错Error processing
执行命令:qmake modbus_ups_mlrl.pro modbus_ups_mlrl.pro文件内容: TEMPLATE = vclib CONFIG +=qt debug thread QT ...
- html中的块元素(Block)和内联元素(Inline)(转)
我们首先要了解,所有的html元素,都要么是块元素(block).要么是内联元素(inline).下面了解一下块元素.内联元素各自的特点: 块元素(block)的特点: 1.总是在新行上开始:2.高度 ...