POJ 2240Arbitrage(Floyd)
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
System Crawler (2015-11-24)
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
先输入货币的种类,然后接着是每个货币的兑换关系,问是否有一种货币能增值,也就是通过某种兑换关系是g[i][i] >1
初始化傻逼地将g设成了INF,白白贡献了4次WA
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
const int MAX = ;
const int INF = << ;
int n;
double g[MAX][MAX];
map<string,int> m;
void Floyd()
{
for(int k = ; k <= n; k++)
{
for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
{
if(g[i][k] != && g[k][j] != && g[i][j] < g[i][k]*g[k][j])
{
g[i][j] = g[i][k]*g[k][j];
}
}
}
}
}
int main()
{
int num = ;
while(scanf("%d", &n) != EOF && n)
{
int t;
char temp[],str[];
double rat;
m.clear();
for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
g[i][j] = ;
}
for(int i = ; i <= n; i++)
{
scanf("%s", temp);
m[temp] = i;
}
scanf("%d", &t);
for(int i = ; i <= t; i++)
{
scanf("%s%lf%s",temp,&rat,str);
g[ m[temp] ][ m[str] ] = rat;
}
Floyd();
int flag = ;
for(int i = ; i <= n; i++)
{
if(g[i][i] != && g[i][i] > 1.0)
{
flag = ;
break;
}
}
printf("Case %d: ",++num);
if(flag)
printf("Yes\n");
else
printf("No\n");
}
return ;
}
POJ 2240Arbitrage(Floyd)的更多相关文章
- POJ 2139 Six Degrees of Cowvin Bacon (Floyd)
题意:如果两头牛在同一部电影中出现过,那么这两头牛的度就为1, 如果这两头牛a,b没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2.以此类推,a与b之间有n头媒介牛, ...
- Stockbroker Grapevine - poj 1125 (Floyd算法)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30454 Accepted: 16659 Description S ...
- POJ题目(转)
http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法: (1)枚举. (poj1753,poj29 ...
- Stockbroker Grapevine(floyd)
http://poj.org/problem?id=1125 题意: 首先,题目可能有多组测试数据,每个测试数据的第一行为经纪人数量N(当N=0时, 输入数据结束),然后接下来N行描述第i(1< ...
- (floyd)佛洛伊德算法
Floyd–Warshall(简称Floyd算法)是一种著名的解决任意两点间的最短路径(All Paris Shortest Paths,APSP)的算法.从表面上粗看,Floyd算法是一个非常简单的 ...
- [CodeForces - 296D]Greg and Graph(floyd)
Description 题意:给定一个有向图,一共有N个点,给邻接矩阵.依次去掉N个节点,每一次去掉一个节点的同时,将其直接与当前节点相连的边和当前节点连出的边都需要去除,输出N个数,表示去掉当前节点 ...
- Repeater POJ - 3768 (分形)
Repeater POJ - 3768 Harmony is indispensible in our daily life and no one can live without it----may ...
- Booksort POJ - 3460 (IDA*)
Description The Leiden University Library has millions of books. When a student wants to borrow a ce ...
- Radar Installation POJ - 1328(贪心)
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. ...
随机推荐
- 工作流模式与K2实现--(2)
结构化过程 这两个模式的共同点在于:模式所涉及流程的执行路径是由运行时决定的,而非设计时确定.包括:Arbitrary cycles(强制循环模式) .Implicit termination( ...
- C语言 const常量讲解
//const的本质 //const本质上是伪常量,无法用于数组初始化以及全局变量初始化 //原因在于const仅仅限定变量无法直接赋值,但是却可以通过指针间接赋值 //例如局部常量在栈区,而不在静态 ...
- jquery 获取select框选中的值示例一则
$('#MODULE_TYPE').change(function(){ var moduleType=$(this).children('option:selected').val();//这就是s ...
- C#中小数点后保留两位小数,四舍五入的函数及使用方法
Math.Round(45.367,2) //Returns 45.37 Math.Round(45.365,2) //Returns 45.36 C#中的Round()不是我 ...
- Android开发探秘之二:导入存在的项目及其注意事项
网上看到有jsoup写的例子,就下载下来进行了研究,但是发现不会导入,于是就百度一下,发现了方法:也就是依次点击“File”->“Import”->“General”->“Exist ...
- 20145314郑凯杰《信息安全系统设计基础》GDB调试32位汇编堆栈分析
20145314郑凯杰<信息安全系统设计基础>GDB调试32位汇编堆栈分析 本篇博客将对第五周博客中的GDB调试32位汇编堆栈进行分析 首先放上以前环境配置的图: 图1: 测试代码: #i ...
- WIN7下USB多点触摸,一次发多个数据包的延迟问题,重要!
这个问题很常见, 花了差不多一个星期时间来解决.硬件相关的东西太多坑了,而且这些坑不像代码那样可见. 使用混合模式,每次最多报告2个点.如果是5点则需要上报三次. 问题就来了,atmel的CTP最 ...
- [BZOJ 2456]Mode(神奇的抵销)
题意:求一串数的众数(保证次数的出现次数超过一半),n<=500000 很简单是不是……快拍一下不就行了吗,不超时呢=W=,不过……尼玛空间只有1M…… 于是此题就成了神题(理解成智商题= =本 ...
- C#基础知识系列六(静态类和静态类成员)
静态类 静态类与非静态类基本相同,但存在一个区别:静态类不能实例化. 也就是说,不能使用 new 关键字创建静态类类型的变量. 因为没有实例变量,所以要使用类名本身访问静态类的成员. 例如,如果名为 ...
- Javascript基础系列之(五)关键字和保留字 (keyword)
关键字不可以作为变量名或者函数名 break case catch continue default delete do else finally for function if in instanc ...