题目链接

分析:

以前没做出来,今天看了一遍题竟然直接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. 关于DPM(Deformable Part Model)算法中模型结构的解释

    关于可变部件模型的描写叙述在作者[2010 PAMI]Object Detection with Discriminatively Trained Part Based Models的论文中已经有说明 ...

  2. poj--1579--(DFS+记忆化搜索之经典)

    记忆化搜索   记忆化搜索:算法上依然是搜索的流程,但是搜索到的一些解用 动态规划的那种思想和模式作一些保存. 一般说来,动态规划总要遍历所有的状态,而搜索可以排除一些无效状态. 更重要的是搜索还可以 ...

  3. C primer plus 读书笔记第十二章

    C的强大功能之一在于它允许我们控制程序的细节.C的内存管理系统正是这种控制能力的例子.它通过让我们决定哪些函数知道哪些变量以及一个变量在程序中存在多长时间来实现这些控制. 1.存储类及其说明符 主要的 ...

  4. iOS人脸识别(CoreImage)

    1.从初始UIImage获取一个CIImage对象. 2.创建一个用于分析对象的CIContext. 3.通过type和options参数创建一个CIDetector实例. type参数指定了要识别的 ...

  5. CALayer的基本操作

     CALayer简介:   CALayer又称为层. 在每一个UIView内部都有一个Layer这样的属性. UIView之所以能够显示,就是因为它里面有这个一个层,才具有显示的功能. 我们通过操作C ...

  6. Java基础知识强化之集合框架笔记10:Collection集合使用的步骤

    集合使用的步骤: (1)创建集合对象 (2)创建元素对象 (3)把元素添加到集合 (4)遍历集合:       • 通过集合对象获取迭代器对象 • 通过迭代器对象的hasnext()方法判断是否有元素 ...

  7. Android(java)学习笔记237:多媒体之图形的变化处理

    1.图形的缩放 (1)布局文件activity_main.xml如下: <LinearLayout xmlns:android="http://schemas.android.com/ ...

  8. HDU 4455(dp)

    题意:给定一个序列ai,个数为n.再给出一系列w:对于每个w,求序列中,所有长度为w的连续子串中的权值和,子串权值为子串中不同数的个数. 思路:动态规划,用dp[w]表示当前长度为w的时候的权值和.显 ...

  9. 网页调用外部APP

    <activity android:name=".MainActivity" android:label="@string/app_name"> & ...

  10. 用js给html设置style

    [html] view plaincopyprint? 原贴地址:<a href="http://heichong.iteye.com/blog/860698">htt ...