poj 2240 Arbitrage
来源:互联网 发布:阿里云创建个人网站 编辑:程序博客网 时间:2024/06/05 14:53
<span style="background-color: rgb(255, 255, 255);"><strong><span style="font-size:18px;">这是一个货币交换问题,就是问你货币交换之后能不能赚到钱,我用数组存储,G[i][i]存储的是第i种货币交换若干次得到的第i种货币的比率,如果大于1就赚了,否则没有赚;用FLOYED求最大回报</span></strong></span><pre name="code" class="cpp">/*********************************************** * Author: fisty * Created Time: 2015/2/16 21:44:34 * File Name : four_I.cpp *********************************************** */#include <iostream>#include <cstring>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <bitset>#include <algorithm>using namespace std;#define Debug(x) cout << #x << " " << x <<endl#define Memset(x, a) memset(x, a, sizeof(x))const int INF = 0x3f3f3f3f;typedef long long LL;typedef pair<int, int> P;#define FOR(i, a, b) for(int i = a;i < b; i++)#define MAX_N 1001int n, m;map<string, int> mp;void ID(string s, int i){ mp[s] = i;}double G[MAX_N][MAX_N];int main() { //freopen("in.cpp", "r", stdin); cin.tie(0); ios::sync_with_stdio(false); int cnt = 1; while(cin >> n){ if(!n) break; FOR(i, 1, n+1){ string s; cin >> s; ID(s, i); } //自己给自己汇率为1,其他为0 FOR(i, 1, n+1){ FOR(j, 1, n+1){ G[i][j] = 0; if(i == j){ G[i][j] = 1; } } } cin >> m; FOR(i, 0, m){ string u, v; double cost; cin >> u >> cost >> v; int e1 = mp[u]; int e2 = mp[v]; G[e1][e2] = cost ; } for(int k = 1;k <= n; k++){ for(int i = 1;i <= n; i++){ for(int j = 1;j <= n; j++){ if(G[i][j] < G[i][k] * G[k][j]) G[i][j] = G[i][k] * G[k][j]; } } } int ok = 0; for(int i = 1;i <= n; i++){ if(G[i][i] > 1){ ok = 1; break; } } cout << "Case " << cnt++ << ": "; if(ok) cout << "Yes" << endl; else cout << "No" <<endl; } return 0;}
0 0
- POJ 2240 Arbitrage
- poj 2240 Arbitrage
- POJ 2240 Arbitrage (Floyd)
- poj 2240Arbitrage(Floyd)
- POJ 2240 Arbitrage Floyd
- Poj 2240 Arbitrage
- POJ 2240 Arbitrage
- poj 2240 Arbitrage
- POJ 2240 Arbitrage (spfa)
- POJ 2240 Arbitrage
- POJ 2240 Arbitrage
- Poj 2240 Arbitrage
- POJ 2240 Arbitrage
- POJ 2240 Arbitrage
- POJ 2240 Arbitrage
- POJ 2240 Arbitrage
- POJ-2240-Arbitrage
- poj 2240 Arbitrage
- NSTimer 实战
- SOJ.SubDiagonal Paths
- 5 Intent 方式的TabHost 选项卡
- JavaScript如何创建dictionary对象
- MFC 根据需要调整对话框大小
- poj 2240 Arbitrage
- ubuntu 12.04 sudo apt-get update 错误
- ios 图片旋转放大加移动
- 5 Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'
- 一个普通消费者的 Windows 10 测评
- cd命令
- impress.js
- Ananagrams
- 我的2014