POJ 1860
须要推断是否有正权环存在,Bellman-Ford算法就能够辣~
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Edge
{
int u,v;
double r,c;
}edge[210];
int n,m,s,k;
double w;
double d[105];
int bellmanford()
{
for(int i=1;i<=n;i++)
d[i]=0.0;
d[s]=w;
int i;
for(i=1;i<=n;i++)
{
bool flag = false;
for(int j=1;j<k;j++)
{
int x=edge[j].u;
int y=edge[j].v;
if(d[y]<(d[x]-edge[j].c)*edge[j].r)
{
flag = true ;
d[y] = (d[x]-edge[j].c)*edge[j].r;
}
}
if(!flag) return false;
}
for(int i=1;i<k;i++)
{
if(d[edge[i].v]<((d[edge[i].u]-edge[i].c)*edge[i].r))
return true;
}
return false;
}
int main()
{
while(scanf("%d%d%d%lf",&n,&m,&s,&w)!=EOF)
{
int a,b;
double rab,cab,rba,cba;
k=1;
while(m--)
{
scanf("%d%d%lf%lf%lf%lf",&a,&b,&rab,&cab,&rba,&cba);
edge[k].u=a;
edge[k].v=b;
edge[k].r=rab;
edge[k].c=cab;
k++;
edge[k].u=b;
edge[k].v=a;
edge[k].r=rba;
edge[k].c=cba;
k++;
}
int ans=bellmanford();
if(ans) printf("YES\n");
else printf("NO\n");
} return 0;
}
POJ 1860的更多相关文章
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- poj 1860 Currency Exchange (SPFA、正权回路 bellman-ford)
链接:poj 1860 题意:给定n中货币.以及它们之间的税率.A货币转化为B货币的公式为 B=(V-Cab)*Rab,当中V为A的货币量, 求货币S通过若干此转换,再转换为原本的货币时是否会添加 分 ...
- POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...
- POJ 1860——Currency Exchange——————【最短路、SPFA判正环】
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- poj - 1860 Currency Exchange Bellman-Ford 判断正环
Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...
- POJ 1860 Currency Exchange (Bellman-Ford)
题目链接:POJ 1860 Description Several currency exchange points are working in our city. Let us suppose t ...
- POJ 1860(spfa)
http://poj.org/problem?id=1860 题意:汇率转换,与之前的2240有点类似,不同的是那个题它去换钱的时候,是不需要手续费的,这个题是需要手续费的,这是个很大的不同. 思路: ...
- POJ 1860 Currency Exchange 最短路 难度:0
http://poj.org/problem?id=1860 #include <cstdio> //#include <queue> //#include <deque ...
- POJ 1860 Currency Exchange (SPFA松弛)
题目链接:http://poj.org/problem?id=1860 题意是给你n种货币,下面m种交换的方式,拥有第s种货币V元.问你最后经过任意转换可不可能有升值.下面给你货币u和货币v,r1是u ...
随机推荐
- hdu4001
参考博客http://www.cppblog.com/aswmtjdsj/archive/2011/09/04/155049.aspx 维护4根双扫描线,左右和上下.暴力枚举,复杂度O(n^2). # ...
- C#中SortedList类的使用
C#中SortedList类 命名空间:System.Collections 程序集:mscorlib(在mscorlib.dll中) 语法:public class SortedList : IDi ...
- 批处理创建数据库(Sql Server)
ylbtech-Miscellaneos:批处理创建数据库(Sql Server) 1.A,资源(Resource) - 创建数据返回顶部 1.A.1,InstallDatabases.cmd - 编 ...
- 矩阵压缩写法 scipy spark.ml.linalg里都有,CRS,CCS
CRS 表示:Compressed Row Storage CCS 表示:Compressed Column Storage CRS的表示参考: https://blog.csdn.net/buptf ...
- [转载]使用expect实现shell自动交互
FROM:http://www.nginx.cn/1934.html shell脚本需要交互的地方可以使用here文档是实现,但是有些命令却需要用户手动去就交互如passwd.scp 对自动部署免去用 ...
- iptables 使用场景
25 Most Frequently Used Linux IPTables Rules Examples by RAMESH NATARAJAN on JUNE 14, 2011 At a firs ...
- Android模块编译过程中的错误no rules to make target
今天花了不少时间在纠正一个编译错误: make: *** No rule to make target `out/target/common/obj/JAVA_LIBRARIES/sqlite-jdb ...
- java.lang.IllegalArgumentException: Wrong state classs
java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class cn.et ...
- Business Process and SAP ERP
1. Definition of Organisation - Organizations are created entities within and through which people i ...
- java 字符深入知识,待整理
'编',"编", 为什么获取到的字节数组长度不一样 http://www.cnblogs.com/yongdaimi/p/5899328.html Unicode 官网 http ...