HDU1217 (Floyd简单变形)
Arbitrage
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5794 Accepted Submission(s): 2683
Your job is to write a program that takes a list of currency exchange rates as input and then determines whether arbitrage is possible or not.
Test cases are separated from each other by a blank line. Input is terminated by a value of zero (0) for n.
0
/*
ID: LinKArftc
PROG: 1217.cpp
LANG: C++
*/ #include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define randin srand((unsigned int)time(NULL))
#define input freopen("input.txt","r",stdin)
#define debug(s) cout << "s = " << s << endl;
#define outstars cout << "*************" << endl;
const double PI = acos(-1.0);
const double e = exp(1.0);
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
typedef long long ll; const int maxn = ;
int n, m;
double table[maxn][maxn]; void floyd() {
for (int k = ; k <= n; k ++) {
for (int i = ; i <= n; i ++) {
for (int j = ; j <= n; j ++) {
table[i][j] = max(table[i][j], table[i][k] * table[k][j]);
}
}
}
} int main() {
//input;
int _t = ;
while (~scanf("%d", &n) && n) {
map <string, int> mp;
string str, str1;
int cnt = ;
for (int i = ; i <= n; i ++) {
cin >> str;
mp[str] = cnt ++;
}
memset(table, , sizeof(table));
scanf("%d", &m);
double change;
for (int i = ; i <= m; i ++) {
cin >> str >> change >> str1;
table[mp[str]][mp[str1]] = change;
}
floyd();
bool flag = false;
for (int i = ; i <= n; i ++) {
if (table[i][i] - 1.0 > eps) {
flag = true;
break;
}
}
if (flag) printf("Case %d: Yes\n", _t ++);
else printf("Case %d: No\n", _t ++);
} return ;
}
HDU1217 (Floyd简单变形)的更多相关文章
- POJ2240——Arbitrage(Floyd算法变形)
Arbitrage DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform o ...
- POJ 1125 Stockbroker Grapevine【floyd简单应用】
链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- Uvaoj 10048 - Audiophobia(Floyd算法变形)
1 /* 题目大意: 从一个点到达另一个点有多条路径,求这多条路经中最大噪音值的最小值! . 思路:最多有100个点,然后又是多次查询,想都不用想,Floyd算法走起! */ #include< ...
- hdu1217 floyd
floyd一遍即可.如果floyd后值有变大就是 #include<map> #include<string> #include<stdio.h> #include ...
- HDU1248 (完全背包简单变形)
寒冰王座 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- B. Mr. Kitayuta's Colorful Graph,二维并查集,一个简单变形就可以水过了~~
B. Mr. Kitayuta's Colorful Graph -> Link <- 题目链接在上面,题目比较长,就不贴出来了,不过这是道很好的题,很多方法都可以做,真心邀请去A了这 ...
- UVA 562 Dividing coins 分硬币(01背包,简单变形)
题意:一袋硬币两人分,要么公平分,要么不公平,如果能公平分,输出0,否则输出分成两半的最小差距. 思路:将提供的整袋钱的总价取一半来进行01背包,如果能分出出来,就是最佳分法.否则背包容量为一半总价的 ...
- POJ 2240 Arbitrage【Bellman_ford坑】
链接: http://poj.org/problem?id=2240 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- 实现了一个简单的cage变形器
今天实现了一个简单变形器,可以用一个网格的形状影响另一个网格的形状. 如图,蓝色网格的形状被灰色网格操控. 当前的算法非常简单,就是计算蓝色网格每个点到灰色网格每个点的距离,以距离x次方的倒数作为权重 ...
随机推荐
- TortoiseSVN的安装使用
下面分享一篇关于TortoiseSVN的安装以及使用 1.运行TortoiseSVN-1.6.6.17493-win32-svn-1.6.6.msi程序, 开始安装 2.点击Next, 下一步 3.选 ...
- 牛客 小a与星际探索
链接:https://ac.nowcoder.com/acm/contest/317/C来源:牛客网 小a正在玩一款星际探索游戏,小a需要驾驶着飞船从1号星球出发前往n号星球.其中每个星球有一个能量指 ...
- LeetCode 876——链表的中间结点
1. 题目 给定一个带有头结点 head 的非空单链表,返回链表的中间结点. 如果有两个中间结点,则返回第二个中间结点. 示例 1: 输入:[1,2,3,4,5] 输出:此列表中的结点 3 (序列化形 ...
- 目标检测之Faster-RCNN的pytorch代码详解(模型训练篇)
本文所用代码gayhub的地址:https://github.com/chenyuntc/simple-faster-rcnn-pytorch (非本人所写,博文只是解释代码) 好长时间没有发博客了 ...
- wampserver 安装后 启动失败的解决方法
安装后启动, 显示 发生未知的异常 wampmanager.exe .... 解决方法 === 其实下载页面说了,先下载 vc的运行库,页面上有链接, 他给的是vc10的,我按照做,失败 查了无数资 ...
- UVA 11884 A Shooting Game(记忆化搜索)
A and B are playing a shooting game on a battlefield consisting of square-shaped unit blocks. The bl ...
- D - 小木棒
D - 小木棒 Time Limit: 1000/1000MS (C++/Others) Memory Limit: 65536/65536KB (C++/Others) Problem Descri ...
- Javascript Array和String的互转换
Array类可以如下定义: var aValues = new Array(); 如果预先知道数组的长度,可以用参数传递长度 var aValues = new Array(20); -------- ...
- online community
online community spectrum https://spectrum.chat/xgqfrms https://community.xgqfrms.xyz/ https://spect ...
- Nginx 学习笔记之安装篇
在windows下安装Nginx其实非常简单,只需如下几个步骤: 1. 在Nginx官网下载相应版本的安装程序,上面有最新版.稳定版等各种版本,正式运营的项目建议下载最新的稳定版 2.将下载后的压缩包 ...