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. ...
随机推荐
- 关于URL编码/javascript/js url 编码
一.问题的由来 URL就是网址,只要上网,就一定会用到. 一般来说,URL只能使用英文字母.阿拉伯数字和某些标点符号,不能使用其他文字和符号.比如,世界上有英文字母的网址 “http://www.ab ...
- ajax技术的应用?
1,百度输入后的提示 2,新浪登录之后只刷新用户名
- 变态跳台阶-一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
class Solution { public: int jumpFloorII(int number) { ) ; ) ; *jumpFloorII(number-); } };
- 解决memcached不能远程访问的问题
之前安装好memcached之后,一直是在本机连接使用的,没有出现问题,今天我改用从另一台机器连接到memcached时,却怎么也连接不上.后来一直想大概是防火墙的问题,关闭了防火墙后问题依然存在. ...
- [CareerCup] 11.6 Search a 2D Matrix 搜索一个二维矩阵
11.6 Given an M x N matrix in which each row and each column is sorted in ascending order, write a m ...
- 实验一(不知道怎么上传.docx格式)
北京电子科技学院(BESTI) 实 验 报 告 课程:深入理解计算机系统 班级:1353 姓名:魏静静 文艺 刘虹辰 学号:20135302 20135331 20 ...
- 利用link标签的disabed属性大面积的对其他标签元素的CSS样式进行替换操作
由于平时对元素样式的控制基本上只是3,4个,所以一般用Jquery的时候直接使用$(element).css();这个方法,或者使用$(element).addClass()方法完成样式操作.对于小范 ...
- Ubuntu下eclipse安装svn插件
好记性不如烂笔头,碰见一个不大不小的问题,记录下. 系统:Ubuntu 12.04 Eclipse:eclipse-jee-kepler-R-linux-gtk.tar.gz subclipse:1. ...
- 全解┃OpenStack Newton发布,23家中国企业上榜(转载)
(转载自Openstack中文社区) 陈, 翔 2016-10-8 | 暂无评论 美国奥斯汀时间10月6日(北京时间6日24点),OpenStack Newton版本正式发布,在可扩展性.可靠性和用户 ...
- Bootstrap3.0学习第十九轮(JavaScript插件——标签页)
详情请看 http://aehyok.com/Blog/Detail/46.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...