题目链接

分析:

以前没做出来,今天看了一遍题竟然直接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. 玩转OpenStack网络Neutron(2)--使用Open vSwitch实现VLAN类型租户网络

    欢迎转载,转载请保留原作者信息 欢迎交流学习,共同进步! 作者:颜海峰 个人博客:http://yanheven.github.io 微博:海峰_云计算 http://weibo.com/344736 ...

  2. C++ 求阶乘 四种方法

    来总结下求阶乘的各种方法哈. 写在最前:①各个代码仅仅是提供了求阶乘的思路,以便在实际须要时再来编码,代码并不健壮!②各个程序都在1到10内測试正确. 代码一: #include<iostrea ...

  3. EditText 密码属性

    <EditText android:id="@+id/et_password" android:layout_width="match_parent" a ...

  4. (转)cocos2dx 内存管理

    原文地址:http://blog.csdn.net/ring0hx/article/details/7946397 cocos2dx的内存管理移植自Objective-C, 对于没有接触过OC的C++ ...

  5. ios中框架介绍

    ios中框架介绍 参考博客: 参考文章:框架介绍 框架介绍 框架就是一个目录,一个目录包含了共享库,访问共享库里面的代码的头文件,和其他的图片和声音的资源文件.一个共享库定义的方法和函数可以被应用程序 ...

  6. [转] Java多线程发展简史

    这篇文章,大部分内容,是周五我做的一个关于如何进行Java多线程编程的Knowledge Sharing的一个整理,我希望能对Java从第一个版本开始,在多线程编程方面的大事件和发展脉络有一个描述,并 ...

  7. Java的容器小结

    1. 各个类与接口的关系:

  8. linux 调试

    strace gdb tcpdump valgrind perf

  9. 动态代理 Proxy InvocationHandler

      前奏 代理模式 代理模式是常用的java设计模式,他的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事后处理消息等. 代理类与委托类之间通常 ...

  10. Jquery小东西收集

    1. $(document).ready(),$(function(){}),$(window).load(),window.onload的关系与区别 $(document).ready(functi ...