题目大意:

给你一个汇率图, 让你判断能否根据汇率盈利

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
#define INF 0xfffffff
#define maxn 50 char P[maxn][maxn];
double G[maxn][maxn];
int n, m; bool Floyd()
{
for(int k=0; k<n; k++)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(G[i][j] < G[i][k] * G[k][j])
{
G[i][j] = G[i][k] * G[k][j];
}
}
}
} for(int i=0; i<n; i++)
{
if(G[i][i] > 1)
return true;
}
return false;
}
int num(char str[])
{
for(int i=0; i<n; i++)
{
if( strcmp(str,P[i]) == 0 )
return i;
}
return -1;
}
int main()
{
char str[maxn];
int a, b, cas = 1;
double c;
while(scanf("%d",&n), n)
{
memset(G,0,sizeof(G)); for(int i=0; i<n; i++)
{
scanf("%s",P[i]);
G[i][i] = 1;
} scanf("%d",&m); for(int i=0; i<m; i++)
{
scanf("%s",str);
a = num(str);
scanf("%lf",&c);
scanf("%s",str);
b = num(str);
G[a][b] = c;
}
printf("Case %d: ",cas++); if( Floyd() )
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}

  

poj2240 - Arbitrage(汇率问题,floyd)的更多相关文章

  1. POJ2240——Arbitrage(Floyd算法变形)

    Arbitrage DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform o ...

  2. POJ2240 Arbitrage(Floyd判负环)

    跑完Floyd后,d[u][u]就表示从u点出发可以经过所有n个点回到u点的最短路,因此只要根据数组对角线的信息就能判断是否存在负环. #include<cstdio> #include& ...

  3. UVA 436 - Arbitrage (II)(floyd)

    UVA 436 - Arbitrage (II) 题目链接 题意:给定一些国家货币的汇率.问是否能通过不断换货币使钱得到增长 思路:floyd,完事后推断一下有没有连到自己能大于1的情况 代码: #i ...

  4. POJ-2240 Arbitrage BellmanFord查可循环圈

    题目链接:https://cn.vjudge.net/problem/POJ-2240 题意 套利(Arbitrage)就是通过不断兑换外币,使得自己钱变多的行为 给出一些汇率 问能不能套利 思路 马 ...

  5. uva 104 Arbitrage (DP + floyd)

    uva 104 Arbitrage Description Download as PDF Background The use of computers in the finance industr ...

  6. POJ 2240 - Arbitrage(bellman_ford & floyd)

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

  7. POJ2240 Arbitrage(最短路)

    题目链接. 题意: 根据汇率可以将一种金币换成其他的金币,求最后能否赚到比原来更多的金币. 分析: 最短路的求法,用floyd. #include <iostream> #include ...

  8. poj-------(2240)Arbitrage(最短路)

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15640   Accepted: 6563 Descri ...

  9. POJ-2240 -Arbitrage(Bellman)

    题目链接:Arbitrage 让这题坑了,精度损失的厉害.用赋值的话.直接所有变成0.00了,无奈下,我仅仅好往里输了,和POJ1860一样找正环,代码也差点儿相同,略微改改就能够了,可是这个题精度损 ...

随机推荐

  1. 整理Git的命令使用

    Git是一个开源的分布式版本号控制系统,用以有效.快速的处理从非常小到非常大的项目版本号管理.Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源代码的版本号 ...

  2. android-个性化进度条

    1.案例效果图 2.准备素材                                progress1.png(78*78)              progress2.png(78*78) ...

  3. Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec command

    错误如下: Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibEx ...

  4. 2015 UESTC Winter Training #10【Northeastern Europe 2009】

    2015 UESTC Winter Training #10 Northeastern Europe 2009 最近集训都不在状态啊,嘛,上午一直在练车,比赛时也是刚吃过午饭,状态不好也难免,下次比赛 ...

  5. MySQL无法登录服务器解决方法

    提示:#2000 无法登录 MySQL 服务器 今天用本机装了个phpMyAdmin,版本3.4.8,想用它来连一台内网服务器上的Mysql,于是乎修改phpMyAdmin配置文件config.inc ...

  6. MySQL user表root用户误删除后恢复

    mysql user表root 用户误删除后恢复root用户 方法/步骤 1.停止mysql服务:在mysql安装目录下找到my.ini:在my.ini中找到以下片段[mysqld]:另起一行加入代码 ...

  7. Knockoutjs官网翻译系列(一)

    最近马上要开始一个新项目的研发,作为第一次mvvm应用的尝试,我决定使用knockoutjs框架.作为学习的开始就从官网的Document翻译开始吧,这样会增加印象并加入自己的思考,说是翻译也并不是纯 ...

  8. arp断网攻击解决办法

    局域网中有这个提示arp断网攻击是正常的,说明防火墙已经拦截了,是有人用P2P工具控制你的网速,或者是局域网有机器中病毒了也会有这样的提示,不过不用担心,今天给大家带来几个防止arp断网攻击的办法,希 ...

  9. Linux进程或线程绑定到CPU

    Linux进程或线程绑定到CPU 为了让程序拥有更好的性能,有时候需要将进程或线程绑定到特定的CPU,这样可以减少调度的开销和保护关键进程或线程. 进程绑定到CPU Linux提供一个接口,可以将进程 ...

  10. Yii 框架里数据库操作详解

    增:1 第一种 $post=new Post; $post->title='sample post'; $post->content='content for the sample pos ...