POJ
来源:互联网 发布:数据分析合同 编辑:程序博客网 时间:2024/06/07 18:55
Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar buys 0.5 British pound, 1 British pound buys 10.0 French francs, and 1 French franc buys 0.21 US dollar.
用map将字符串当做点,Bellman-Ford求正权回路……
#include<iostream>#include<queue>#include<math.h>#include<stdio.h>#include<string>#include<map>using namespace std;#define N 1000+5#define LL long long int#define pow(a) ((a)*(a))#define INF 0x3f3f3f3f#define mem(arr,a) memset(arr,a,sizeof(arr))map<string, int>maps;struct edge{ int from; int to; double rate;};edge es[N];int V, E;double d[N];int counts = 1;int bellman(int s){ mem(d, 0); d[s] = 1; int cnt = 0; while (1){ cnt++; bool update = false;; for (int i = 0; i < E; i++){ if (d[es[i].to]<d[es[i].from] * es[i].rate){ d[es[i].to] = d[es[i].from] * es[i].rate; update = true; } } if (!update)return false; if (cnt == V)return true; } return false;}int main(){ while (cin >> V) { if (V == 0)break; for (int i = 1; i <= V; i++){ string s; cin >> s; maps[s] = i; } cin >> E; for (int i = 0; i < E; i++){ string a, b; double rate; cin >> a; cin >> rate; cin >> b; es[i].rate = rate; es[i].from = maps[a]; es[i].to = maps[b]; } printf("Case %d: ", counts++); if (bellman(1))cout << "Yes" << endl; else cout << "No" << endl; } return 0;}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- sqlite 数据库实操
- 青岛往事(三)
- SpringMVC学习笔记(一)-概述、HelloWorld、@RequestMapping、@RequestParam
- Hive 窗口函数(Windowing Functions)
- 服务器搭建:servlet+dao+javabean+jsp实现简单的用户登录
- POJ
- 博弈——GG and MM
- DevOps企业实践指南(9): ITSM与Agile的融合
- python统计文本中单词出现次数
- 核+X参赛小作品:拟真核电厂控制台
- 自定义segue的方向
- matlab中矩阵运算函数
- MATLAB中符号运算
- MATLAB绘制图形