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)的更多相关文章

  1. Poj(2240),Floyd求汇率是不是赚钱

    题目链接:http://poj.org/problem?id=2240. Floyd算法修改一下,我要最大路径(通过转汇率变到最大)改成max. #include <iostream> # ...

  2. poj 2240 floyd算法

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17349   Accepted: 7304 Descri ...

  3. poj 2240 Arbitrage (Floyd)

    链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...

  4. 最短路(Floyd_Warshall) POJ 2240 Arbitrage

    题目传送门 /* 最短路:Floyd模板题 只要把+改为*就ok了,热闹后判断d[i][i]是否大于1 文件输入的ONLINE_JUDGE少写了个_,WA了N遍:) */ #include <c ...

  5. POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)

    POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...

  6. poj 2240 Arbitrage 题解

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21300   Accepted: 9079 Descri ...

  7. POJ 2240 Arbitrage(floyd)

    http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...

  8. POJ 2240 - Arbitrage(bellman_ford & floyd)

    题意: 给出一些货币和货币之间的兑换比率,问是否可以使某种货币经过一些列兑换之后,货币值增加. 举例说就是1美元经过一些兑换之后,超过1美元.可以输出Yes,否则输出No. 分析: 首先我们要把货币之 ...

  9. 【floyd】 poj 2240

    #include <iostream> #include <map> #include <string> #include <memory.h> usi ...

随机推荐

  1. fork与vfork

    先看一个fork的例子: ; int main(void) { int var, pid; ; ) { printf("vfork error"); exit(-); } ) { ...

  2. Drupal 7.31SQL注入getshell漏洞利用详解及EXP

    0x00 这个漏洞威力确实很大,而且Drupal用的也比较多,使用Fuzzing跑字典应该可以扫出很多漏洞主机,但是做批量可能会对对方网站造成很大的损失,所以我也就只是写个Exp不再深入下去. 0x0 ...

  3. hibernate4中使用Session doWork()方法进行jdbc操作(代码)

    Hibernate3.3.2版本中getSession().connection()已被弃用,hibernate4中官方推荐使用Session doWork()方法进行jdbc操作 首先看看Work接 ...

  4. c# 日期函数[string.Format----GetDateTimeFormats]格式 .【转帖备查】

    DateTime dt = DateTime.Now;Label1.Text = dt.ToString();//2005-11-5 13:21:25Label2.Text = dt.ToFileTi ...

  5. CF451A Game With Sticks 水题

    Codeforces Round #258 (Div. 2) Game With Sticks A. Game With Sticks time limit per test 1 second mem ...

  6. SQL获取日期格式

    ) + ' ' + CONVERT(VARCHAR, DATEPART(hh, GetDate())) + ':' + ) AS Date ),) ),) ),) as DateTime) as [D ...

  7. R语言 奇怪的NA

    > 1+NA [1] NA > NA==1 [1] NA > c(NA,1:50) [1] NA 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  8. Google Protocol Buffer 简单介绍

    以下内容主要整理自官方文档. 为什么使用 Protocol Buffers .proto文件 Protocol Buffers 语法 编译.proto文件 Protocol Buffers API 枚 ...

  9. 6.3.28微信需群主确认才可进群&发GIF动图功能内测开始了

    昨天下午有网友收到微信6.3.28新版内测邀请,不过这个内部体验目前貌似只对安卓手机开放,苹果的IOS系统还不支持,会提示“你当前使用的是非安卓设备,不建议下载安卓体验包,但你仍可邀请朋友尝鲜”.最新 ...

  10. 修改dedecms默认文章来源 "未知"改为关键词

    在dedecms后台发表文章时文章来源是可选的,有时我们没有选择或没填写,那么前台默认文章来源即“未知”.如何将dedecms默认文章来源改为自己想要的关键词呢?即将“未知”改为“keyword”呢? ...