poj 2240(floyd)
http://poj.org/problem?id=2240
题意:有些人会利用货币的不用汇率来进行套现,比如1美元换0.5英镑,而1英镑又可以换10法郎,而1法郎又可以换0.21的美元,那么经过货币的汇率转换后,它就可以获得1.05倍原来的美元。
现在给你N中货币,m种货币的汇率,求是否可以获利。
思路:首先这个是给你一些货币,那么我们可以把货币和数字建立一个映射。然后再用他给的汇率以及数字建立一个邻接矩阵。用一次floyd后对对角线的数字进行判断,如果大于1,那么说明可以获利,不然就不能获利。
这个题我用c++是78ms,用G++是700多ms。
#include <stdio.h>
#include <string.h>
#include <map>
#include <string>
#include <iostream> using namespace std; map< string , int > s; double graph[ ][ ]; int main()
{
// freopen("in.txt","r",stdin);
int n,p = ;
while( cin>>n,n )
{
p++;
memset( graph , , sizeof( graph ) );
string a , b;
double m;
int x,mark = ;
for(int i = ; i <= n ; i++ )
{
cin>>a;
s[ a ] = i; //对货币和数字建立一个映射。
}
cin>>x;
for( int i = ; i <= x ; i++ )
{
cin>>a>>m>>b;
graph[ s[ a ] ][ s[ b ] ] = m;
}
for( int k = ; k <= n ; k++ ) //floyd求出两个货币间的最大汇率。
for( int i = ; i <= n ; i++ )
for( int j = ; j <= n ; j++ )
if( graph[ i ][ j ] < graph [ i ][ k ]*graph[ k ][ j ])
graph[ i ][ j ] = graph [ i ][ k ]*graph[ k ][ j ];
for(int i = ; i <= n ; i++ ) //判断。
if( graph[ i ][ i ] > ) mark = ;
if( mark ) printf("Case %d: Yes\n",p);
else printf("Case %d: No\n",p);
}
return ;
}
poj 2240(floyd)的更多相关文章
- Poj(2240),Floyd求汇率是不是赚钱
题目链接:http://poj.org/problem?id=2240. Floyd算法修改一下,我要最大路径(通过转汇率变到最大)改成max. #include <iostream> # ...
- poj 2240 floyd算法
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17349 Accepted: 7304 Descri ...
- poj 2240 Arbitrage (Floyd)
链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...
- 最短路(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)
http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...
- POJ 2240 - Arbitrage(bellman_ford & floyd)
题意: 给出一些货币和货币之间的兑换比率,问是否可以使某种货币经过一些列兑换之后,货币值增加. 举例说就是1美元经过一些兑换之后,超过1美元.可以输出Yes,否则输出No. 分析: 首先我们要把货币之 ...
- 【floyd】 poj 2240
#include <iostream> #include <map> #include <string> #include <memory.h> usi ...
随机推荐
- 全选,全不选,反选的js实现
全选练习 ** 使用复选框上面一个属性判断是否选中 - checked属性 - checked=true:选中 ...
- Yii2 行为
// Step 1: 定义一个将绑定行为的类 class MyClass extends yii\base\Component { // 空的 } // Step 2: 定义一个行为类,他将绑定到My ...
- MySQL分表自增ID解决方案(转)
当我们对MySQL进行分表操作后,将不能依赖MySQL的自动增量来产生唯一ID了,因为数据已经分散到多个表中. 应尽量避免使用自增IP来做为主键,为数据库分表操作带来极大的不便. 在postgreSQ ...
- YII2 实现后台操作记录日志(转)
一.连接linux服务器,创建数据文件 php yii migrate/create user_log 二.修改数据文件 console/migrations/m150721_032220_admin ...
- Linux下vim查看文件名
在vim下编辑时,有时候看不到文件名,不知道编辑的是那个文件,怎么呢,可以按照下面的方法试试. 查看文件名 在正常模式下: :f 或CTRL+G 查看文件的路径 用 :!pwd 可以看当前的详细路径. ...
- Memcached基础知识
主要内容: Memcached基本的工作原理 Memcached的两阶段哈希 Memcached的数据存储方式 Memcached新建Item分配内存过程 Memcached的数据过期方式 Memca ...
- CRect类
类CRect是对Windows结构RECT的封装,凡是能用RECT结构的地方都可以用CRect代替. 结构RECT表示一个矩形的位置和尺寸,其定义为: typedef struct tagRECT{ ...
- 必须知道的.net(继承)
1.继承定义:就是面向对象中类与类之间的一种关系.通过继承,使得子类具有父类的属性和方法,同时子类也可以通过加入新的属性和方法或者修改父类的属性和方法建立新的类层次. 2.CLR支持实现单继承和接口多 ...
- 71 mac boook pro 无 gpu 下caffe 安装
71 mac boook pro 无 gpu 下caffe 安装 1.首先安装homebrew工具,相当于Mac下的yum或apt ruby -e "$(curl -fsSL https:/ ...
- spring ioc原理
最近,买了本Spring入门书:spring In Action .大致浏览了下感觉还不错.就是入门了点.Manning的书还是不错的,我虽然不像哪些只看Manning书的人那样专注于Manning, ...