POJ2240 Arbitrage(最短路)
题目链接。
题意:
根据汇率可以将一种金币换成其他的金币,求最后能否赚到比原来更多的金币。
分析:
最短路的求法,用floyd.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map> using namespace std; const int maxn = ; map<string, int> a;
double G[maxn][maxn];
int cn ; int main() {
int n, m, u, v, cnt = ;
char s[], s1[], s2[];
double rate; while(cin >> n) {
if(n == ) break; a.clear(); cn = ; for(int i=; i<n; i++) {
for(int j=; j<n; j++) {
G[i][j] = 1.0;
}
} for(int i=; i<n; i++) {
scanf("%s", s);
if(a.count(s) == ) a[s] = cn++;
} cin >> m;
for(int i=; i<m; i++) {
cin >> s1 >> rate >> s2;
if(a.count(s1) == ) u = a[s1];
else continue; if(a.count(s2) == ) v = a[s2];
else continue;
G[u][v] = rate;
} for(int k=; k<n; k++) {
for(int i=; i<n; i++) {
for(int j=; j<n; j++) {
G[i][j] = max(G[i][j], G[i][k]*G[k][j]);
}
}
} bool flag = false;
for(int i=; i<n; i++) {
if(G[i][i] > 1.0) {
flag = true;
break;
}
} if(flag) printf("Case %d: Yes\n", ++cnt);
else printf("Case %d: No\n", ++cnt);
} return ;
}
POJ2240 Arbitrage(最短路)的更多相关文章
- poj-------(2240)Arbitrage(最短路)
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15640 Accepted: 6563 Descri ...
- POJ 2240 Arbitrage(最短路 套汇)
题意 给你n种币种之间的汇率关系 推断是否能形成套汇现象 即某币种多次换为其他币种再换回来结果比原来多 基础的最短路 仅仅是加号换为了乘号 #include<cstdio> #in ...
- POJ-2240 -Arbitrage(Bellman)
题目链接:Arbitrage 让这题坑了,精度损失的厉害.用赋值的话.直接所有变成0.00了,无奈下,我仅仅好往里输了,和POJ1860一样找正环,代码也差点儿相同,略微改改就能够了,可是这个题精度损 ...
- POJ-2240 Arbitrage BellmanFord查可循环圈
题目链接:https://cn.vjudge.net/problem/POJ-2240 题意 套利(Arbitrage)就是通过不断兑换外币,使得自己钱变多的行为 给出一些汇率 问能不能套利 思路 马 ...
- POJ2240 Arbitrage(Floyd判负环)
跑完Floyd后,d[u][u]就表示从u点出发可以经过所有n个点回到u点的最短路,因此只要根据数组对角线的信息就能判断是否存在负环. #include<cstdio> #include& ...
- POJ2240——Arbitrage(Floyd算法变形)
Arbitrage DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform o ...
- POJ 2240 && ZOJ 1082 Arbitrage 最短路,c++ stl pass g++ tle 难度:0
http://poj.org/problem?id=2240 用log化乘法为加法找正圈 c++ 110ms,g++tle #include <string> #include <m ...
- poj 2240 Arbitrage (最短路 bellman_ford)
题目:http://poj.org/problem?id=2240 题意:给定n个货币名称,给m个货币之间的汇率,求会不会增加 和1860差不多,求有没有正环 刚开始没对,不知道为什么用 double ...
- poj2240 - Arbitrage(汇率问题,floyd)
题目大意: 给你一个汇率图, 让你判断能否根据汇率盈利 #include <iostream> #include <cstdlib> #include <cstdio&g ...
随机推荐
- Project Euler:Problem 55 Lychrel numbers
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...
- POJ 2075 Tangled in Cables (c++/java)
http://poj.org/problem?id=2075 题目大意: 给你一些人名,然后给你n条连接这些人名所拥有的房子的路,求用最小的代价求连接这些房子的花费是否满足要求. 思路: 昨天20分钟 ...
- Android应用打包安装过程具体解释
Android应用打包安装过程(Run as Android Application ): 1,过程:Android Project --> Compilation and Packaging ...
- Linux下有线无线网络配置------命令模式
1. 列出启用网络设备的所有信息: ifconfig 2. 将网络设备设置为启用或者不启用 不启用设备eth0 ifconfig eth0 down 启用设备eth0: Will bring eth0 ...
- Content Provider Basics ——Content Provider基础
A content provider manages access to a central repository of data. A provider is part of an Android ...
- retrofit2 okhttp3 RxJava butterknife 示例
eclipse的jar包配置 eclipse中貌似用不了butterknife buildToolsVersion "23.0.2" defaultConfig { applica ...
- codevs1051单词接龙(栈)
/* 看到n的范围就觉得这个不可能是DP啥的 因为这个接龙的规则十分的简单 只要前缀相同即可 所以先按字典序排一遍 这样保证符合规则的一定挨着 然后弄一个stack 每次拿栈顶元素看看待入栈的元素是否 ...
- python中的generator, iterator, iterabel
先来看看如果遇到一个对象,如何判断其是否是这三种类型: from types import GeneratorType from collectiuons import Iterable, Itera ...
- Java编程思想-注解生成外部例子代码
如果本文帮助到您,请点击下面的链接,这是本人的网站,以示鼓励,谢谢!链接绝对安全! 本人的网站 java注解属于java中高大上的功能,许多开源框架都使用了java注解的功能.比如spring,hib ...
- webconfig的设置节点几个说明
有助于深入理解webconfig <?xml version="1.0" encoding="utf-8" ?> <configuration ...