I - Arbitrage
#include<algorithm>
#include<queue>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<string>
#include<map>
#include<iostream>
using namespace std; const int maxn = ;
const int oo = 0xfffffff;
const double StartMoney = ; struct node
{
int y;
double rate;
node(int y, double r):y(y), rate(r){}
};
vector<node> G[maxn];
double v[maxn]; void Initialization(int s, int N)//初始化变量
{
for(int i=; i<=N; i++)
v[i] = -oo; v[s] = StartMoney;
}
int Spfa(int s)
{
queue<int> Q;
Q.push(s); while(Q.size())
{
int i = Q.front();Q.pop();
int len = G[i].size(); for(int j=; j<len; j++)
{
node q = G[i][j];
double k = v[i] * q.rate; if(k > v[q.y])
{
v[q.y] = k;
Q.push(q.y);
}
} if(v[s] > StartMoney)
return ;
} return ;
} int main()
{
int N, M, t=; while(scanf("%d", &N), N)
{
int i;
double r;
string A, B;
map<string, int> a; for(i=; i<=N; i++)
{
cin >> A;
a[A] = i;
} scanf("%d", &M); for(i=; i<=M; i++)
{
cin >> A >> r >> B;
int x = a[A], y = a[B];
G[x].push_back(node(y, r));
} for(i=; i<=N; i++)
{
Initialization(i, N);
if(Spfa(i) == )
break;
} if(i <= N)
printf("Case %d: Yes\n", t++);
else
printf("Case %d: No\n", t++); for(i=; i<=N; i++)
G[i].clear();
} return ;
}
I - Arbitrage的更多相关文章
- poj 2240 Arbitrage
Time Limit: 1000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Java class name ...
- UVa 104 - Arbitrage(Floyd动态规划)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- Arbitrage(bellman_ford)
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16652 Accepted: 7004 Descri ...
- 最短路(Floyd_Warshall) POJ 2240 Arbitrage
题目传送门 /* 最短路:Floyd模板题 只要把+改为*就ok了,热闹后判断d[i][i]是否大于1 文件输入的ONLINE_JUDGE少写了个_,WA了N遍:) */ #include <c ...
- poj-------(2240)Arbitrage(最短路)
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15640 Accepted: 6563 Descri ...
- ZOJ 1092 Arbitrage
原题链接 题目大意:Arbitrage这个单词的解释是“套利交易”,就是利用几个币种之间的汇率差价来赚钱.比如人民币兑美元6:1,美元兑欧元1.5:1,欧元兑人民币10:1,那么用9元人民币可以换1. ...
- poj 2240 Arbitrage bellman-ford算法
点击打开链接 Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13434 Accepted: 5657 ...
- HDU 1217 Arbitrage (Floyd)
Arbitrage http://acm.hdu.edu.cn/showproblem.php?pid=1217 Problem Description Arbitrage is the use of ...
- POJ 2240 Arbitrage (求负环)
Arbitrage 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/I Description Arbitrage is the ...
- POJ2240——Arbitrage(Floyd算法变形)
Arbitrage DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform o ...
随机推荐
- 补充一下sql server(临时表)
说明:(1).临时表其实是放在数据库tempdb里的一个用户表:(2).TempTableName必须带“#”,“#"可以是一个或者两个,以#(局部)或##(全局)开头的表,这种表在会话期间 ...
- OC - 24.CABasicAnimation
概述 简介 CABasicAnimation是抽象类CAPropertyAnimation的子类,可以直接使用 CABasicAnimation又称基本动画,从fromValue到toValue按照指 ...
- js判断是否在iframe中
1.方式一 if (self.frameElement && self.frameElement.tagName == "IFRAME") { alert('在if ...
- 【工具篇】xshell
SSH.telnet.串口登录等,类似Secure CRT,蛮好用的. 中文显示乱码的解决方法,file->properties,在Encoding那里修改为UTF-8 修改颜色,点Edit修改 ...
- WARN [main] conf.HiveConf (HiveConf.java:initialize(1488)) - DEPRECATED
问题描述:hive 关于告警问题的解决:WARN [main] conf.HiveConf (HiveConf.java:initialize(1488)) - DEPRECATED: Config ...
- [转]jQuery,javascript获得网页的高度和宽度
网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.body.offsetWi ...
- YII 集成jquery
- uboot总结:uboot配置和启动过程2(mkconfig分析)
说明:文件位置:在uboot的目录下,文件名为:mkconfig.本身是一个脚本文件. 它的主要作用的是: (1)创建一个重要的符号链接 (2)创建一个config.mk文件(在include目录下) ...
- CoreLocation MKMapView
高德开发者平台 有开发指南 iOS9配置网络: <key>NSAppTransportSecurity</key> <dict> <key>NSAllo ...
- EasyUI篇のDataGrid
HTML: <table id="dg"></table> 或者 <div id="dg"></div> JS: ...