题目链接

题意:

根据汇率可以将一种金币换成其他的金币,求最后能否赚到比原来更多的金币。

分析:

最短路的求法,用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(最短路)的更多相关文章

  1. poj-------(2240)Arbitrage(最短路)

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15640   Accepted: 6563 Descri ...

  2. POJ 2240 Arbitrage(最短路 套汇)

    题意  给你n种币种之间的汇率关系  推断是否能形成套汇现象  即某币种多次换为其他币种再换回来结果比原来多 基础的最短路  仅仅是加号换为了乘号 #include<cstdio> #in ...

  3. POJ-2240 -Arbitrage(Bellman)

    题目链接:Arbitrage 让这题坑了,精度损失的厉害.用赋值的话.直接所有变成0.00了,无奈下,我仅仅好往里输了,和POJ1860一样找正环,代码也差点儿相同,略微改改就能够了,可是这个题精度损 ...

  4. POJ-2240 Arbitrage BellmanFord查可循环圈

    题目链接:https://cn.vjudge.net/problem/POJ-2240 题意 套利(Arbitrage)就是通过不断兑换外币,使得自己钱变多的行为 给出一些汇率 问能不能套利 思路 马 ...

  5. POJ2240 Arbitrage(Floyd判负环)

    跑完Floyd后,d[u][u]就表示从u点出发可以经过所有n个点回到u点的最短路,因此只要根据数组对角线的信息就能判断是否存在负环. #include<cstdio> #include& ...

  6. POJ2240——Arbitrage(Floyd算法变形)

    Arbitrage DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform o ...

  7. 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 ...

  8. poj 2240 Arbitrage (最短路 bellman_ford)

    题目:http://poj.org/problem?id=2240 题意:给定n个货币名称,给m个货币之间的汇率,求会不会增加 和1860差不多,求有没有正环 刚开始没对,不知道为什么用 double ...

  9. poj2240 - Arbitrage(汇率问题,floyd)

    题目大意: 给你一个汇率图, 让你判断能否根据汇率盈利 #include <iostream> #include <cstdlib> #include <cstdio&g ...

随机推荐

  1. [置顶] iOS 名片识别代码

    采用的是惠普图片识别SDK.本代码可以识别中文.代码改自 http://www.cocoachina.com/bbs/read.php?tid=123463 . 图片就不贴了,123463中的效果是可 ...

  2. [PWA] 17. Cache the photo

    To cache photo, You need to spreate cache db to save the photo. So in wittr example, we cache the te ...

  3. [PWA] 11. Serve skeleton cache for root

    Intead of cache the root floder, we want to cache skeleton instead. self.addEventListener('install', ...

  4. Linux基础系列—Linux体系结构和Linux内核结构

    /** ****************************************************************************** * @author    暴走的小 ...

  5. checkbox 全选/取消

    <html><script language=javascript>function selectAll(){var a = document.getElementsByTag ...

  6. Web api 文档以及测试工具配置

    第一步: 创建web api 在nuget 上搜索 webapitestclient (包含预发行版) 然后在 /Areas/HelpPage/Views/Help/Api.cshtml 末尾 添加 ...

  7. (转)iFrame高度自适应

    第一种方法:代码简单,兼容性还可以,大家可以先测试下: function SetWinHeight(obj) { var win=obj; if (document.getElementById) { ...

  8. css.day02.eg

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. Pgsql 里面 COALESCE的用法

    有这种要求,更新自己本身的字段的某个值进行加或者减, 常规方法: UPDATE tbl_kintai_print_his SET print_time = now(), print_emp_cd = ...

  10. 安装PHP过程中,make步骤报错:(集合网络上各种解决方法)

    安装PHP过程中,make步骤报错:(集合网络上各种解决方法) (1)-liconv -o sapi/fpm/php-fpm /usr/bin/ld: cannot find -liconv coll ...