Arbitrage(floyd)
http://poj.org/problem?id=2240
#include <stdio.h>
#include <string.h>
const int INF=<<;
double dis[][];
char str[][];
int n,m; void init()
{
for (int i = ; i <= n; i ++)
{
for (int j = ; j <= n; j ++)
{
dis[i][j] = ;
}
}
}
int Deal(char *s)
{
for (int i = ; i <= n; i ++)
{
if (!strcmp(s,str[i]))
return i;
}
return ;
}
void floyd()
{
for (int k = ; k <= n; k ++)
{
for (int i = ; i <= n; i ++)
{
for (int j = ; j <= n; j ++)
{
if (dis[i][j] < dis[i][k]*dis[k][j])
dis[i][j] = dis[i][k]*dis[k][j];
}
}
} }
int main()
{
int o = ;
while(~scanf("%d%*c",&n)&&n)
{
++o;
char ss[],ss1[];
double rate;
init();
for (int i = ; i <= n; i ++)
{
scanf("%s",str[i]);
}
scanf("%d%*c",&m);
while(m--)
{
scanf("%s",ss);
int i = Deal(ss);
scanf("%lf",&rate);
scanf("%s",ss1);
int j = Deal(ss1);
dis[i][j] = rate;
}
floyd();
int flag = ;
for (int i = ; i <= n; i ++)
{
if (dis[i][i] > )
flag = ;
}
if (flag)
printf("Case %d: Yes\n",o);
else
printf("Case %d: No\n",o);
}
return ;
}
Arbitrage(floyd)的更多相关文章
- HDU 1217 Arbitrage (Floyd)
Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...
- POJ2240——Arbitrage(Floyd算法变形)
Arbitrage DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform o ...
- Nyoj Arbitrage(Floyd or spfa or Bellman-Ford)
描述Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a curren ...
- hdu 1217 Arbitrage (最小生成树)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1217 /************************************************* ...
- UVa 104 - Arbitrage(Floyd动态规划)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- HDOJ 1217 Arbitrage(拟最短路,floyd算法)
Arbitrage Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- UVA 436 - Arbitrage (II)(floyd)
UVA 436 - Arbitrage (II) 题目链接 题意:给定一些国家货币的汇率.问是否能通过不断换货币使钱得到增长 思路:floyd,完事后推断一下有没有连到自己能大于1的情况 代码: #i ...
- uva 104 Arbitrage (DP + floyd)
uva 104 Arbitrage Description Download as PDF Background The use of computers in the finance industr ...
- POJ 2240 - Arbitrage(bellman_ford & floyd)
题意: 给出一些货币和货币之间的兑换比率,问是否可以使某种货币经过一些列兑换之后,货币值增加. 举例说就是1美元经过一些兑换之后,超过1美元.可以输出Yes,否则输出No. 分析: 首先我们要把货币之 ...
随机推荐
- mysql_数据查询_单表查询
1.单表查询: 1.1选中表中若干列: SELECT子句的<目标列表达式>可以是表中属性列,也可以是表达式,还可以是字符常量. SELECT Sname,'year of birth:', ...
- abstract class和interface 抽象类与接口类的区别
抽象类与类型定义相关: 接口类与行为规范相关: 接口类不是类型. 抽象类:是不完整的类,函数实现未定义:可以继承,不可以实例化. 接口类:接口类不是类:是类间交互的规范:不能继承.不能实例化,只能实现 ...
- day10-函数基础知识
函数 什么是函数 把工具事先准备好,然后下次使用的时候,直接使用就行了.我们的函数就是工具 为何用函数 1.遇到重复的功能只能重复编写实现代码,代码冗余 2.功能需要扩展时,需要找出所有实现该功能的地 ...
- 基于fpga的256m的SDRAM控制器
2018/7/26 受教于邓堪文老师,开始真真学习控制sdram 由于自己买的sdram模块是256的,原来老师的是128,所以边学边改,不知道最后好不好使,但是我有信心 一.sdram的初始化 sd ...
- pop的运用
pop():弹出列表最后一个元素 练习题: num_list = [12, 45, 34,13, 100, 24, 56, 74, 109] one_list = [] two_list = [] t ...
- 第十节:pandas之loc()、iloc()与ix()索引
- (问题待解决)sql查询不显示前置‘0’的问题
SELECT * , ,),() ) ' end)) from CourseBooksNotes ),)),)+'秒'; ),)),)),)+'秒'
- 【codeforces 764D】Timofey and rectangles
[题目链接]:http://codeforces.com/contest/764/problem/D [题意] 给你n个矩形,以左下角坐标和右上角坐标的形式给出; (保证矩形的边长为奇数) 问你有没有 ...
- 【codeforces 801A】Vicious Keyboard
[题目链接]:http://codeforces.com/contest/801/problem/A [题意] 一个字符串只由VK组成; 让你修改一个字符; 使得剩下的字符串里面子串VK的个数最大; ...
- qwb VS 去污棒
qwb VS 去污棒 Time Limit: 2 Sec Memory Limit: 256 MB Description qwb表白学姐失败后,郁郁寡欢,整天坐在太阳底下赏月.在外人看来,他每天自 ...