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 ...
随机推荐
- [置顶]
docker web-GUI DockerUI和Shipyard对比
DockerUI和Shipyard对比 相似 基于Docker API,提供等同Docker命令行的大部分功能,支持container管理,image管理. web页面查看和管理容器和镜像,均能批量管 ...
- hdu4001
参考博客http://www.cppblog.com/aswmtjdsj/archive/2011/09/04/155049.aspx 维护4根双扫描线,左右和上下.暴力枚举,复杂度O(n^2). # ...
- 访问php程序无法解析,排查步骤
1.安装lamp后,php程序没有被解析 (1) apachectl -M 看是否加载了libphp5.so ,apachectl -M 这个命令查看动态libphp5.so的是否由apache加载 ...
- django开发环境部署之pip、virtualenv、virtualenvwrapper
step1:安装pip 在python中可以使用easy_install和pip安装python拓展但推荐使用pip Don't use easy_install, unless you like s ...
- python pip安装lxml失败(转)
今天想要试试beautifulsoup4,安装的时候很顺利,然后就准备安装lxml作为解析器,没想到安装时pip直接给我报了一整页的错误. 解决过程 查看了一下错误提示,其中有如下一段: ****** ...
- 机器学习第4课:多变量线性回归(Linear Regression with Multiple Variables)
4.1 多维特征 目前为止,我们探讨了单变量/特征的回归模型,现在我们对房价模型增加更多的特征, 例如房间数楼层等,构成一个含有多个变量的模型,模型中的特征为(x1,x2,...,xn).
- Storm sql 简单测试
准备工作: 1.安装Kafka,启动,以及创建相应的topic 1.启动kafka bin/kafka-server-start.sh config/server.properties > /d ...
- 2017.7.18 linux下ELK环境搭建
参考来自:Linux日志分析ELK环境搭建 另一篇博文:2017.7.18 windows下ELK环境搭建 0 版本说明 因为ELK从5.0开始只支持jdk 1.8,但是项目中使用的是JDK 1 ...
- P6 EPPM 安装和配置指南
In This Section Installation and Configuration Guide Manual Installation Guides P6 Professional Inst ...
- UI_UITableView_搭建
创建 tableView UITableViewStyle 有两种选择 #pragma mark - 创建 tableView - (void)createTableView { // 枚举类型共同拥 ...