poj2240 - Arbitrage(汇率问题,floyd)
题目大意:
给你一个汇率图, 让你判断能否根据汇率盈利
#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)的更多相关文章
- POJ2240——Arbitrage(Floyd算法变形)
Arbitrage DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform o ...
- POJ2240 Arbitrage(Floyd判负环)
跑完Floyd后,d[u][u]就表示从u点出发可以经过所有n个点回到u点的最短路,因此只要根据数组对角线的信息就能判断是否存在负环. #include<cstdio> #include& ...
- UVA 436 - Arbitrage (II)(floyd)
UVA 436 - Arbitrage (II) 题目链接 题意:给定一些国家货币的汇率.问是否能通过不断换货币使钱得到增长 思路:floyd,完事后推断一下有没有连到自己能大于1的情况 代码: #i ...
- POJ-2240 Arbitrage BellmanFord查可循环圈
题目链接:https://cn.vjudge.net/problem/POJ-2240 题意 套利(Arbitrage)就是通过不断兑换外币,使得自己钱变多的行为 给出一些汇率 问能不能套利 思路 马 ...
- 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. 分析: 首先我们要把货币之 ...
- POJ2240 Arbitrage(最短路)
题目链接. 题意: 根据汇率可以将一种金币换成其他的金币,求最后能否赚到比原来更多的金币. 分析: 最短路的求法,用floyd. #include <iostream> #include ...
- poj-------(2240)Arbitrage(最短路)
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15640 Accepted: 6563 Descri ...
- POJ-2240 -Arbitrage(Bellman)
题目链接:Arbitrage 让这题坑了,精度损失的厉害.用赋值的话.直接所有变成0.00了,无奈下,我仅仅好往里输了,和POJ1860一样找正环,代码也差点儿相同,略微改改就能够了,可是这个题精度损 ...
随机推荐
- ScheduledExecutorService定时周期运行指定的任务
一:简单说明 ScheduleExecutorService接口中有四个重要的方法,当中scheduleAtFixedRate和scheduleWithFixedDelay在实现定时程序时比較方便. ...
- 小胖学PHP总结1-----PHP的数据类型
PHP一共支持8种原始类型.包含4中标量类型,即:boolean(布尔型).integer(整形).float/double(浮点型)和string(字符串型):两种复合类型,即:array(数组)和 ...
- 利用d3.js绘制雷达图
利用d3,js将数据可视化,能够做到数据与代码的分离.方便以后改动数据. 这次利用d3.js绘制了一个五维的雷达图.即将多个对象的五种属性在一张图上对照. 数据写入data.csv.数据类型写入typ ...
- 数据库系统——B+树索引
原文来自于:http://dblab.cs.toronto.edu/courses/443/2013/05.btree-index.html 1. B+树索引概述 在上一篇文章中,我们讨论了关于ind ...
- [Flux] Stores
Store, in Flux which manager the state of the application. You can use EventEmiiter to listen to the ...
- php 数组排序 (转)
// @param array $list 查询结果 // @param string $field 排序的字段名 // @param array $sortby 排序类型 // asc正向排序 de ...
- 【iOS】3D Touch
文章内容来源于Apple的开发者文档:https://developer.apple.com/library/content/documentation/UserExperience/Conceptu ...
- Entity Framework CodeFirst------数据迁移(二)
众所周知当我们的项目涉及到数据库时,随着需求或大或小的 变更后,我们之前设计好的数据模型会发生部分的更改,导致数据表.或者数据字段的增加.修改等,这个时候我们就需要对数据库结构进行修改,如果我们之前采 ...
- centos7 部署ssserver
centos7 部署shadowsocks服务端 为什么要选centos7? 以后centos7 肯定是主流,在不重要的环境还是尽量使用新系统吧 centos7 的坑 默认可能会有firewall 或 ...
- (转)Css样式兼容IE6,IE7,FIREFOX的写法
根据FF和IE对一些符号识别的差异,我们可以单独对FF以及IE定义样式,例子: 区别IE6与FF: background:orange;*background:blue; 区别I ...