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 ...
随机推荐
- java的几个概念AOP、IOC、DI、DIP、工厂模式、IOC容器
1.AOP:面向切面编程 把一些公共类,比如日志类.安全类.数据库连接类.系统统一的认证.权限管理类.资源池(如数据库连接池的管理).性能监控等做成一个公共类,当其他类需要时,进行注入(调用).这样这 ...
- #if 条件编译
1.格式: #if constant-expression statements #elif constant-expression statements #else statements #endi ...
- ES6里关于类的拓展(一)
大多数面向对象的编程语言都支持类和类继承的特性,而JS却不支持这些特性,只能通过其他方法定义并关联多个相似的对象,这种状态一直延续到了ES5.由于类似的库层出不穷,最终还是在ECMAScript 6中 ...
- 2. Spring Boot返回json数据【从零开始学Spring Boot】
在做如下操作之前,我们对之前的Hello进行简单的修改,我们新建一个包com.kfit.test.web然后新建一个类HelloControoler,然后修改App.Java类,主要是的这个类就是一个 ...
- 系统封装 如何修改别人的PE为己所用
我们以修改"我心如水 WIN7PE_16.99.1 维护版.ISO"为例,整个ISO的核心文件就是这个BOOT.WIM,我们先把他提取出来. 然后用在本教程第一章学到的东西,用AI ...
- android:Cordova Android, hello Cordova ,PhoneGap android
文章来自:http://blog.csdn.net/intbird 官方文档: http://cordova.apache.org/docs/en/5.0.0//index.html intbird的 ...
- Exposing the Outlook Password Secrets
Exposing the Outlook Password Secrets - www.SecurityXploded.comhttp://securityxploded.com/outlookpas ...
- Unity里面的自动寻路(一)
来自:http://www.narkii.com/club/forum.php?mod=viewthread&tid=269146&highlight=Unity%E9%87%8C%E ...
- 使用SQLite存储数据
一.SQLiteAndroid 为了让我们能够更加方便地管理数据库, 专门提供了一个SQLiteOpenHelper 帮助类,借助这个类就可以非常简单地对数据库进行创建和升级. 1.SQLiteOpe ...
- VB断点调试
最近都在敲机房收费系统,这个系统是我们第一次自己在没有源代码的情况下进行的系统. 写程序的时候逻辑非常重要,可是我们还要清楚非常多时候你以为的并非你以为的! 就像在敲机房的时候,我们明明理清了逻辑.并 ...