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-条件和循环
条件 Demo1: if i < 10: print('i<10') elif i == 0: print('i=0 ') else: print('...') Demo1说明了以下几点: ...
- SQL 存储过程 超市小票打印
create database chaoshils--创建一个数据库 go use chaoshils--使用这个数据库 go create table gongying--创建一个供应商的表格 ( ...
- java实现24点游戏代码
import java.util.Arrays;import java.util.Scanner; public class Test07 { public static void main(S ...
- 43. Multiply Strings (String)
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- Intersection(Check)
Intersection http://poj.org/problem?id=1410 Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- 使用CSS实现透明边框的效果——兼容当前各种主流浏览器[xyytIT]
这个效果可是通过代码实现的哦,在不同浏览器下都可以正常显示 对于html中使用CSS实现透明边框的效果,主要有以下四种属性设置方法,但由于 这些属性兼容性并不是很好,单一使用会造成不同浏览器显示效果不 ...
- 'WebElement' object is not iterable
checkbox.html源码: <html> <head> <meta http-equiv="content-type" content=&quo ...
- php Pthread 多线程 (四) 共享内存
有些时候我们希望在多个线程中共享一些需要的数据,我们可以使用shmop扩展. <?php class Count extends Thread { private $name = ''; pub ...
- discuz模板引擎语法
论坛的首页模板:forum/discuz.htm 版块的内容模板:forum/forumdisplay.htm 主题的查看模板:forum/viewthread.htm 帖子的内容模板:forum/p ...
- 【原创】有关Silverlight中自动生成的类中 没有WCF层edmx模型新加入的对象 原因分析。
前端页面层: 编译老是不通过,报如下如所示错误: -- 然后下意识的查了下 生成的cs文件,没有搜到根据edmx 生成的 对应的类. 结果整理: 1.尽管在 edmx 模 ...