PKU1860--Currency Exchange
来源:互联网 发布:淘宝直播运营公司 编辑:程序博客网 时间:2024/05/29 03:41
本题需要注意的是,起点不一定是从1开始,在初始化的时候也需注意。
#include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>#include <math.h>#define Min(a,b) a<b?a:b#define Max(a,b) a<b?b:a#define M 105*5#define INF 999999999using namespace std;int n,m;int k,s;double dis[M];double v;struct Edge{int from,to;double R;double C;};struct Edge edge[M];bool Bellman_Ford(){int i,j;for(i=1;i<M;i++){dis[i]=0;}dis[s]=v;bool flag;for(i=1;i<n;i++){flag=false;for(j=1;j<=k;j++){if(dis[edge[j].to]<(dis[edge[j].from]-edge[j].C)*edge[j].R){dis[edge[j].to]=(dis[edge[j].from]-edge[j].C)*edge[j].R;flag=true;}}if(!flag)break;}for(j=1;j<=k;j++){if(dis[edge[j].to]<(dis[edge[j].from]-edge[j].C)*edge[j].R)return true;}return false;}int main(){int i;while(scanf("%d%d%d%lf",&n,&m,&s,&v)!=EOF){k=1;for(i=0;i<m;i++){int a,b;double Rab,Rba,Cab,Cba;scanf("%d%d%lf%lf%lf%lf",&a,&b,&Rab,&Cab,&Rba,&Cba);edge[k].from=a,edge[k].to=b,edge[k].R=Rab,edge[k++].C=Cab;edge[k].from=b,edge[k].to=a,edge[k].R=Rba,edge[k++].C=Cba;}if(Bellman_Ford())printf("YES\n");elseprintf("NO\n");}return 0;}
0 0
- PKU1860--Currency Exchange
- PKU1860 Currency Exchange bellman求最长路
- Currency Exchange
- Currency Exchange
- Currency Exchange
- Currency Exchange
- Currency Exchange
- Currency Exchange
- Currency Exchange
- Currency Exchange
- Currency Exchange
- ZOJ-1058-Currency Exchange
- ZOJ1058 Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- Poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- 黑马程序员泛型与使用举例
- 数据,云计算
- arm工作模式
- 一个资深程序员看12306 (二)
- 南阳 47 过河问题
- PKU1860--Currency Exchange
- 做任何事情前确定owner
- hover事件
- HPUX 11.31下更改设备名【转载】
- 电商b2c结构图
- HashMap与Hashtable的区别
- 用 block 代替delegate传值和回调
- 回复他人前先回复自己能让自己避免大部分的矛盾
- JAVA JDK API 源码学习 - Arrays.equals