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 ...
随机推荐
- 18 4Sum(寻找四个数之和为指定数的集合Medium)
题目意思:给一个乱序数组,在里面寻找三个数之和为target的所有情况,这些情况不能重复,增序排列 思路:采用3Sum的做法 ps:有见一种用hash的,存任意两个元素的和,然后变成3sum问题,需要 ...
- DEDE更改版权信息
DEDECMSV5.7版本出现后,在前台网页底部会出现织梦版权信息 “powered by dedecms”,很多人都不知道怎么去掉 1. 方法一: 在include/dedesql.classs. ...
- php基础知识【函数】(9)数学和对象类函数
一.数学 abs -- 绝对值 ceil -- 进一法取整 floor -- 舍去法取整 fmod -- 返回除法的浮点数余数 round -- 对浮点数进行四舍五入 sqrt -- 平方根 pi( ...
- ueditor的过滤、转义、格式丢失问题
1. 过滤 http://www.cnblogs.com/Olive116/p/3464495.html 2. 转义 http://segmentfault.com/q/101000000048928 ...
- 20141127 测试使用Word2013书写博客(代码高亮+公式支持)。
PS :又经过几次测试,发现用于Word2010的高亮插件在Word2013上排版效果不是很好,慎用.不过公式编辑倒是挺方便的 测试使用Word2013书写博客. 大概一个月前,使用WindowL ...
- ubuntu 解压rar
Ubuntu下解压rar文件的方法 一般通过默认安装的ubuntu是不能解压rar文件的,只有在安装了rar解压工具之后,才可以解压.其实在ubuntu下安装rar解压工具是非常简单的,只需要两个步骤 ...
- BZOJ 1006 神奇的国度
Description K国是一个热衷三角形的国度,连人的交往也只喜欢三角原则.他们认为三角关系:即AB相互认识,BC相互认识,CA相互认识,是简洁高效的.为了巩固三角关系,K国禁止四边关系,五边关系 ...
- JS论坛地址备忘
论坛: 百度JS吧 CSDN论坛JS版 AS天地会JS区 编程论坛JS版 开源中国JS分享 开源中国JS提问区 德问 JS堂 CSS-JS前端论坛 蓝色理想 ITEYE php100 phpspeak ...
- Unity3d开发IOS游戏 基础
Unity3d开发IOS游戏 基础 @阿龙 - 649998群 1.先说明两个问题,我在WIN7下面的U3D里面,用了雅黑字体,但是导出为ios后,字体就看不见了,这是为什么呢?这是需要在MAC下找 ...
- 电容式触摸控制器PCB布局
在目前市场上可提供的PCB(印刷电路板)基材中,FR4是最常用的一种.FR4是一种玻璃纤维增强型环氧树脂层压板,PCB可以是单层或多层. 在触摸模块的尺寸受限的情况下,使用单层PCB不是总能行得通的, ...