题意:给出n种货币,m中交换关系,给出两种货币汇率和手续费,求能不能通过货币间的兑换使财富增加。

用Bellman_Ford 求出是否有正环,如果有的话就可以无限水松弛,财富可以无限增加。

#include<string.h>
#include<stdio.h>
const int N=110;
const int inf=0x3fffffff;
int start,num,n;
double dist[N],wf;
struct edge
{
int st,ed;
double cost,w;
}e[220];
void addedge(int x,int y,double w,double c)
{
e[num].st=x;e[num].ed=y;e[num].cost=c;e[num++].w=w;
}
int Bellman_Ford()
{
int flag=0,i,u,v,j;
for(i=1;i<=n;i++)
dist[i]=0;
dist[start]=wf;
for(i=1;i<n;i++)//n-1次松弛
{
for(j=0;j<num;j++)
{
u=e[j].st;v=e[j].ed;
if(dist[v]<(dist[u]-e[j].cost)*e[j].w)
{
dist[v]=(dist[u]-e[j].cost)*e[j].w;
flag=1;
}
}
if(flag==0)break;
}
for(i=0;i<num;i++)
if(dist[e[i].ed]<(dist[e[i].st]-e[i].cost)*e[i].w)//有正环
return 1;
return 0;
}
int main()
{
int m,i,x,y;
double a,b,c,d;
while(scanf("%d%d%d%lf",&n,&m,&start,&wf)!=-1)
{
num=0;
for(i=1;i<=m;i++)
{
scanf("%d%d%lf%lf%lf%lf",&x,&y,&a,&b,&c,&d);
addedge(x,y,a,b);
addedge(y,x,c,d);
}
if(Bellman_Ford())
printf("YES\n");
else printf("NO\n");
}
return 0;
}

poj 1860 (Bellman_Ford判断正环)的更多相关文章

  1. Currency Exchange POJ - 1860 spfa判断正环

    //spfa 判断正环 #include<iostream> #include<queue> #include<cstring> using namespace s ...

  2. HDU 1317 XYZZY【Bellman_Ford判断正环】

    题意:给出n个房间,初始在房间1有100的能量值,每次进入一个房间,能量值可能增加也可能减小,(是点权,不是边权),问能否到达终点的时候能量值还为正 这题自己写的时候wa--wa-- 后来看了题解,还 ...

  3. POJ - 1860 Bellman-Ford判正环

    心累,陕西邀请赛学校不支持,可能要自费了.. 思路:套用Bellman-Ford判断负环的思路,把大于改成小于即可判定是否存在从源点能到达的正环.如果存在正环,那么完全多跑几次正环就可以把钱增加到足够 ...

  4. poj 1860 bellman 求正环

    #include<stdio.h> #include<string.h> #include<queue>//只需判断是否有正环路径就可以了 using namesp ...

  5. poj 3259 (Bellman_Ford判断负环)

    题意:John的农场里n块地,m条路连接两块地,k个虫洞,虫洞是一条单向路,不但会把你传送到目的地,而且时间会倒退Ts.我们的任务是知道会不会在从某块地出发后又回来,看到了离开之前的自己. 思路:虫洞 ...

  6. hdu 1317 XYZZY【Bellheman_ford 判断正环小应用】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1317 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  7. poj - 1860 Currency Exchange Bellman-Ford 判断正环

    Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...

  8. Currency Exchange POJ - 1860 (spfa判断正环)

    Several currency exchange points are working in our city. Let us suppose that each point specializes ...

  9. poj1860 兑换货币(bellman ford判断正环)

    传送门:点击打开链接 题目大意:一个城市有n种货币,m个货币交换点,你有v的钱,每个交换点只能交换两种货币,(A换B或者B换A),每一次交换都有独特的汇率和手续费,问你存不存在一种换法使原来的钱更多. ...

随机推荐

  1. source install MacPorts--checking for Tcl configuration... configure: error: Can't find Tcl configuration definitions

    If you installed MacPorts using the package installer, skip this section. To install MacPorts from t ...

  2. ip聚合(百度之星资格赛1003)

    IP聚合 点击这里 Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下, ...

  3. Apriori algorithm

    本文是个人对spmf中example1. mining frequent itemsets by  using the apriori algorithm的学习. What is Apriori? A ...

  4. BCB的博客,以及例子(好多传输文件的例子)

    http://blog.csdn.net/keyu1711/ http://download.csdn.net/user/keyu1711 http://download.csdn.net/user/ ...

  5. Delphi调用安装驱动sys的单元

    unit SysDriver; interface uses windows, winsvc; // jwawinsvc; Type TSysDriver = class(TObject) priva ...

  6. Qt :非window子窗体的透明度设置

    ✿问题的由来            心血来潮,想利用QTimer 配合 setWindowOpacity()方法来实现一个窗体淡入的效果.   ✿实验代码    粗糙的实验代码: void Widge ...

  7. System.Web.Caching.Cache类 缓存 各种缓存依赖

    原文:System.Web.Caching.Cache类 缓存 各种缓存依赖 Cache类,是一个用于缓存常用信息的类.HttpRuntime.Cache以及HttpContext.Current.C ...

  8. poj 2393 Yogurt factory(dp+贪心)

    奶牛们建了一家酸奶厂,在N周内每周需要出货Y_i单位酸奶,第i周成本为C_i,储存费为每周S.求总体最低成本. 贪心策略是维持每周的最低单位成本,每周可能用上周剩下的,也可能生产新的.于是该周单位成本 ...

  9. K-th Number(第k大数)

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 45710   Accepted: 15199 Ca ...

  10. Android九宫格图片(9.png)的讲解与制作

    刚开始学习Android的时候,会见到res/drawable的几个文件里面有*.9.png格式命名的图片文件.起初以为这只是Android素材的一些特殊命名,其实不是.它是能实现图片素材拉伸.收缩不 ...