Billman_ford货币升值——正权回路
都是问货币能不能增多,钻社会制度得空子啊哈哈
唯一不同得是你的起点是任意一个点,这个比较麻烦了,多了一层循环嘞
处理货币名可以用map分配id
然后就是老套的Billman_ford算法了
#include <iostream>
#include <map>
#include <vector>
#include <string.h>
#include <cstdio>
#include <string>
using namespace std;
const int maxn = 40;
map<string,int> id;
double dis[maxn];
struct node{
int from,to;
double v;
node(int f,int t,double va):from(f),to(t),v(va){}
node(){}
};
这次联系了Stl中得容器,熟悉熟悉
int main()
{
int n,m;
string s,a,b;
double v;
int cas = 1;
while(~scanf("%d",&n),n)
{
id.clear();
edge.clear();
for(int i = 1;i <= n;i++)
{
cin>>s;
id[s] = i;
}
scanf("%d",&m);
while(m--)
{
cin>>a;
scanf("%lf",&v);
cin>>b;
edge.push_back(node(id[a],id[b],v));
}
printf("Case %d: ",cas++);
for(int i = 1;i <= n;i++)
{
if(blm(i,n))
{
printf("Yes\n");
break;
}
else if(i == n)printf("No\n");
}
}
return 0;
}
vector<node> edge;
bool blm(int s,int n)
{
for(int i = 1;i <= n;i++)dis[i] = 0;
dis[s] = 1.0;
for(int i = 1;i < n;i++)
{
for(int j = 0;j < edge.size();j++)
{
int from = edge[j].from;
int to = edge[j].to;
double v = edge[j].v;
//cout<<from<<" "<<to<<" "<<v<<endl;
dis[to] = max(dis[to],dis[from] * v);
}
//cout<<"cs"<<endl;
}
for(int i = 0;i < edge.size();i++)
{
int from = edge[i].from;
int to = edge[i].to;
double v = edge[i].v;
if(dis[to] < dis[from] * v)return true;
}
return false;
}
Billman_ford货币升值——正权回路的更多相关文章
- 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19881 Accepted: 711 ...
- poj 1860 Currency Exchange (SPFA、正权回路 bellman-ford)
链接:poj 1860 题意:给定n中货币.以及它们之间的税率.A货币转化为B货币的公式为 B=(V-Cab)*Rab,当中V为A的货币量, 求货币S通过若干此转换,再转换为原本的货币时是否会添加 分 ...
- POJ1860-Currency Exchange (正权回路)【Bellman-Ford】
<题目链接> <转载于 >>> > 题目大意: 有多种汇币,汇币之间可以交换,这需要手续费,当你用100A币交换B币时,A到B的汇率是29.75,手续费是0. ...
- Currency Exchange 货币兑换 Bellman-Ford SPFA 判正权回路
Description Several currency exchange points are working in our city. Let us suppose that each point ...
- [ACM] hdu 1217 Arbitrage (bellman_ford最短路,推断是否有正权回路或Floyed)
Arbitrage Problem Description Arbitrage is the use of discrepancies in currency exchange rates to tr ...
- Bellman_ford货币兑换——正权回路判断
POJ1860 题目大意:你在某一点有一些钱,给定你两点之间钱得兑换规则,问你有没有办法使你手里的钱增多.就是想看看转一圈我的钱能不能增多,出现这一点得条件就是有兑换钱得正权回路,所以选择用bellm ...
- POJ 1860 Currency Exchange(最短路&spfa正权回路)题解
题意:n种钱,m种汇率转换,若ab汇率p,手续费q,则b=(a-q)*p,你有第s种钱v数量,问你能不能通过转化让你的s种钱变多? 思路:因为过程中可能有负权值,用spfa.求是否有正权回路,dis[ ...
- HDU - 1317 ~ SPFA正权回路的判断
题意:有最多一百个房间,房间之间连通,到达另一个房间会消耗能量值或者增加能量值,求是否能从一号房间到达n号房间. 看数据,有定5个房间,下面有5行,第 iii 行代表 iii 号 房间的信息,第一个数 ...
- POJ 3259 Wormholes(最短路&spfa正权回路)题解
题意:给你m条路花费时间(双向正权路径),w个虫洞返回时间(单向负权路径),问你他能不能走一圈回到原点之后,时间倒流. 思路:题意有点难看懂,我们建完边之后找一下是否存在负权回路,存在则能,反之不能. ...
随机推荐
- python生成器(转)
生成器是一种特殊的迭代器,内部支持了生成器协议,不需要明确定义__iter__()和next()方法.生成器通过生成器函数产生,生成器函数可以通过常规的def语句来定义,但是不用return返回,而是 ...
- SciTE: 中文字符支持问题
SciTE: 中文字符支持问题 SciTE(Scintilla Text Editor)是一个体积小巧的文本编辑器. 但是它默认的设置对中文字符处理不好,其实只要对它进行相应的配置,就可以了. 1 ...
- Fiddler 捕获 nodejs 模拟的http请求
1.设置Fiddler Tools->Options-> Connections Allow remote computers to connect: 2.nodejs 请求有多种 2.1 ...
- drupal 7.1 doc
https://www.drupal.org/docs/8/api/database-api/dynamic-queries/count-queries https://www.drupal.org/ ...
- 第五章 二叉树(e1)先序遍历
- 43. Multiply Strings (String)
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- centos 6.5 ftp服务配置及客户端使用
一.ftp服务简介 FTP是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为“文传协议”.用于Internet上的控制文件的双向传输.同时,它也是一个应用程序(Ap ...
- SQL时间格式化 转载备用~
Sel1 取值后格式化{0:d}小型:如2005-5-6{0:D}大型:如2005年5月6日{0:f}完整型 2 当前时间获取 DateTime.Now.ToShortDateString 3 取值中 ...
- snowflake自增ID算法 (PHP版)
/** * SnowFlake ID Generator * Based on Twitter Snowflake to generate unique ID across multiple * da ...
- MySQL相关知识总结
1. 显示所有表 show tables; 还有information_schema数据库里面有tables表,记录了所有表信息 use information_schema; select * fr ...