UVA 436 - Arbitrage (II)(floyd)
UVA 436 - Arbitrage (II)
题意:给定一些国家货币的汇率。问是否能通过不断换货币使钱得到增长
思路:floyd,完事后推断一下有没有连到自己能大于1的情况
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <map>
using namespace std; const int N = 35; int n;
double g[N][N];
map<string, int> hash; int main() {
int cas = 0;
while (~scanf("%d", &n) && n) {
string a, b;
hash.clear();
for (int i = 1; i <= n; i++) {
cin >> a;
hash[a] = i;
}
int m;
double f;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j) g[i][j] = 1.0;
else g[i][j] = 0;
}
}
scanf("%d", &m);
while (m--) {
cin >> a >> f >> b;
int u = hash[a], v = hash[b];
g[u][v] = f;
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
g[i][j] = max(g[i][j], g[i][k] * g[k][j]);
}
}
printf("Case %d: ", ++cas);
int flag = 1;
for (int i = 1; i <= n; i++) {
if (g[i][i] > 1.0) {
printf("Yes\n");
flag = 0;
break;
}
}
if (flag) printf("No\n");
}
return 0;
}
UVA 436 - Arbitrage (II)(floyd)的更多相关文章
- UVa 247 - Calling Circles(Floyd求有向图的传递闭包)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 247 电话圈 (floyd传递闭包 + dfs输出连通分量的点)
题意:输出所有的环: 思路:数据比较小,用三层循环的floyd传递闭包(即两条路通为1,不通为0,如果在一个环中,环中的所有点能互相连通),输出路径用dfs,递归还没有出现过的点(vis),输出并递归 ...
- UVA 11549 CALCULATOR CONUNDRUM(Floyd判圈算法)
CALCULATOR CONUNDRUM Alice got a hold of an old calculator that can display n digits. She was bore ...
- UVA - 247 Calling Circles(Floyd求传递闭包)
题目: 思路: 利用Floyd求传递闭包(mp[i][j] = mp[i][j]||(mp[i][k]&&mp[k][j]);),当mp[i][j]=1&&mp[j][ ...
- UVA 247"Calling Circles"(floyd求传递闭包+SCC)
传送门 题意: 如果两个人相互打电话(直接或间接),则说他们在同一个电话圈里. (a,b) 表示 a 打给 b: 例如,(a,b),(b,c),(c,d),(d,a),则这四个人在同一个电话圈里: 输 ...
- uva 10599 - Robots(II) (dp | 记忆化搜索)
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- UVa 821 网页跳跃(Floyd)
https://vjudge.net/problem/UVA-821 题意:给出一个有向图,任意两点都可相互到达,求任意两点的最短距离的平均值. 思路:求两点的最短距离,用Floyd算法很方便,最后加 ...
- UVa 247 电话圈(Floyd传递闭包)
https://vjudge.net/problem/UVA-247 题意: 如果两个人相互打电话,则说他们在同一个电话圈里.例如,a打给b,b打给c,c打给d,d打给a,则这4个人在同一个圈里:如果 ...
- UVa 11549 计算器谜题(Floyd判圈算法)
https://vjudge.net/problem/UVA-11549 题意: 有一个老式计算器,只能显示n位数字,输入一个整数k,然后反复平方,如果溢出的话,计算器会显示结果的最高n位.如果一直这 ...
随机推荐
- java cocurrent包
1. java.util.concurrent - Java 并发工具包 Java 5 添加了一个新的包到 Java 平台,java.util.concurrent 包.这个包包含有一系列能够让 Ja ...
- NEFU 119
和上一题一样,注意除不尽为0 #include <iostream> #include <cstdio> #include <cstring> #include & ...
- 解决的方法:mysql_connect()不支持请检查mysql模块是否正确载入
故障现象:linux 安装discuz 错误提示:mysql_connect() 不支持请检查mysql模块是否正确载入. 解决的方法:查看/usr/lib/php/modules/ (64位的看/u ...
- USACO 1.2 Transformations (模拟)
模拟题目,依照题目给定的要求变换图形就可以,变换的优先级依次减小. 这个题目我写的非常乱.只是最还还是勉强能够执行 /* ID:twd30651 PROG:transform LANG:C++ */ ...
- [C++设计模式]observer 观察者模式
有这么一种松耦合的需求: 有一些类的对象对类A对象的状态变化非常感兴趣,不会改变类A的对象,也不会被类A的对象改变,想以一种较小的代价观察对类A对象状态变化. 以下的几种方式也能实现上述目的 (1)通 ...
- MFC exe使用C++ dll中的std::string 崩溃
VC6中 MFC exe中 new 纯C++ dll dll 崩溃 我把纯C++的 dll,用/MTd 换成/MDd.就能够了
- invalidate
转载请注明出处: 前言: 本文是我读<Android内核剖析>第13章----View工作原理总结而成的,在此膜拜下作者 .同时真挚地向渴望了解 A ...
- SQL Server 汉字转拼音字母
/* 汉字转拼音首字母 */ create function fun_getPY(@str nvarchar(4000)) returns nvarchar(4000) as begin declar ...
- C# WebAPI小记
新建WebAPI项目 新建一个Model 安装Entity Framework 添加连接字符串 去Web.config 中 <configuration> 节点中最下面添加 在Word中编 ...
- composer的一些操作
版本更新 命令行下:composer self-update 设置中国镜像 composer config -g repo.packagist composer https://packagist.p ...