题目链接

分析:

以前没做出来,今天看了一遍题竟然直接A了。出乎意料。

大意是这样,给定不同的金币的编号,以及他们之间的汇率、手续费,求有没有可能通过不断转换而盈利。

直接用Bellman-ford检测负环的方法检测。

#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int maxn = ;
const int inf = (<<); struct Node {
int u, v;
double r, c;
int next;
}node[maxn]; int n, m, s, cn, head[];
double q, d[]; void add_edge(int u, int v, double r, double c) {
node[cn].u = u;
node[cn].v = v;
node[cn].r = r;
node[cn].c = c;
node[cn].next = head[u];
head[u] = cn++;
} bool bellman_ford(int s) {
for(int i=; i<n; i++) d[i] = -inf;
d[s] = q; for(int i=; i<n-; i++) {
for(int i=; i<cn; i++) {
Node &e = node[i]; if(d[e.u] != -inf && (d[e.u]-e.c)*e.r>d[e.v]) {
d[e.v] = (d[e.u]-e.c)*e.r;
}
}
} for(int i=; i<cn; i++) {
Node &e = node[i]; if(d[e.u] != -inf && (d[e.u]-e.c)*e.r>d[e.v]) {
return true;
}
}
return false;
} int main() {
int u, v;
double r1, c1, r2, c2; while(scanf("%d %d %d %lf", &n, &m, &s, &q) == ) {
cn = ; memset(head, -, sizeof(head)); for(int i=; i<m; i++) {
scanf("%d %d %lf %lf %lf %lf", &u, &v, &r1, &c1, &r2, &c2);
u--; v--;
add_edge(u, v, r1, c1);
add_edge(v, u, r2, c2);
} if(bellman_ford(s-)) printf("YES\n");
else printf("NO\n");
} return ;
}

POJ1860 Currency Exchange(最短路)的更多相关文章

  1. POJ1860——Currency Exchange(BellmanFord算法求最短路)

    Currency Exchange DescriptionSeveral currency exchange points are working in our city. Let us suppos ...

  2. POJ1860 Currency Exchange【最短路-判断环】

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

  3. POJ 1860 Currency Exchange 最短路+负环

    原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Tota ...

  4. POJ1860 Currency Exchange(bellman-ford)

    链接:http://poj.org/problem?id=1860 Currency Exchange Description Several currency exchange points are ...

  5. POJ 1860 Currency Exchange (最短路)

    Currency Exchange Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u S ...

  6. POJ1860:Currency Exchange(BF)

    http://poj.org/problem?id=1860 Description Several currency exchange points are working in our city. ...

  7. poj1860 Currency Exchange(spfa判断正环)

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

  8. POJ1860 Currency Exchange —— spfa求正环

    题目链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Tota ...

  9. POJ-1860 Currency Exchange( Bellman_Ford, 正环 )

    题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...

随机推荐

  1. CF 295E Yaroslav and Points(Splay)

    题目大意: 两个操作 1 id op  把id的位置+op 2 id op  查询在[id.op]之间的全部的数的差 思路: 关键是pushup函数. 自己退一下会发现.跟区间的总和,区间的节点个数有 ...

  2. NDN路由--OSPFN安装与配置

    现在的IP网络的问题已经暴露的很多了,各种改进的网络架构与设想非常多,但其中以基于内容为中心的网络发展最为迅速,其中,NDN的架构最为完整,代码也比较成熟.OSPFN是基于CCNX的,所以之前要安装C ...

  3. Delphi 2007体验!

    Delphi 2007体验! baidu 内容摘要:CodeGear(From Borland) 公司公布了最新的Delphi 2007 For Win32版本号.作为一个 Delphi 的使用者,第 ...

  4. MySQL 通配符学习小结

    MySQL 通配符 SQL的模式匹配同意你使用"_"匹配不论什么单个字符,而"%"匹配随意数目字符(包含零个字符).在 MySQL中,SQL的模式缺省是忽略大写 ...

  5. 解决java.sql.SQLException: Parameter number X is not an OUT parameter--转

    最近独自一个人写项目,孤军奋战的程序猿可真伤不起! Java 调用MYSQL带输入输出参数存储过程时如题错误:java.sql.SQLException: Parameter number X is ...

  6. spring mvc DispatcherServlet详解之前传---前端控制器架构

    前端控制器是整个MVC框架中最为核心的一块,它主要用来拦截符合要求的外部请求,并把请求分发到不同的控制器去处理,根据控制器处理后的结果,生成相应的响应发送到客户端.前端控制器既可以使用Filter实现 ...

  7. How To Cluster Rabbit-MQ--reference

    Foreword This explanation of clustering Rabbit-MQ assumes that you’ve had some experience with Rabbi ...

  8. [转] socket异步编程--libevent的使用

    这篇文章介绍下libevent在socket异步编程中的应用.在一些对性能要求较高的网络应用程序中,为了防止程序阻塞在socket I/O操作上造成程序性能的下降,需要使用异步编程,即程序准备好读写的 ...

  9. svcutil 生成代理类时的问题

    如果有这个的xsd, group内嵌choice的结构: <xs:complexType name="CreateType">        <xs:sequen ...

  10. python字符串replace()方法

    python字符串replace()方法 >>> help(str.replace)Help on method_descriptor:replace(...)    S.repla ...