真是气skr人。。没把d[]换成double。。。de了一上午的bug//

记得用G++提交啊


题目链接:http://poj.org/problem?id=1860

题意:告诉你n个点,m条路。起始点s,还有初始金额money。每条路表示从a->b的汇率和佣金以及b->a的汇率和佣金。你在该点所得是(本金-佣金)*汇率。问你这个人能不能赚钱。

题解:spfa套一下//。记得d[]换成double。具体的看看代码。QWQ。

代码:

 #include<iostream>
#include<stack>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn = ; struct node{
int to;
double r;
double c;
}; vector< node > e[maxn]; int n,m,num;
double money;
double d[maxn];
int inq[maxn]; bool spfa(int s){
for(int i = ; i <= n ;i++){
inq[i] = d[i] = ;
}
queue<int>Q;
Q.push(s);
d[s] = money;
inq[s] = ;
while( !Q.empty() ){
int now = Q.front();
Q.pop();
inq[now] = ;
for(int i = ; i < e[now].size() ; i++){
double rate = e[now][i].r;
double commis = e[now][i].c;
int v = e[now][i].to; if(d[v] < (d[now] - commis) * rate){
d[v] = (d[now] - commis) * rate;
if(inq[v] == ){
inq[v] = ;
Q.push(v);
}
} if(d[s] > money){
return true;
}
} }
return false;
} int main() {
scanf("%d%d%d%lf",&n,&m,&num,&money);
int x,y;
double r,c;
while(m--){
scanf("%d%d%lf%lf",&x,&y,&r,&c);
e[x].push_back((node){y,r,c});
scanf("%lf%lf",&r,&c);
e[y].push_back((node){x,r,c});
}
if(spfa(num))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl; return ;
}

【POJ】1860 Currency Exchange的更多相关文章

  1. 最短路(Bellman_Ford) POJ 1860 Currency Exchange

    题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...

  2. POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)

    POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...

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

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

  4. POJ 1860 Currency Exchange + 2240 Arbitrage + 3259 Wormholes 解题报告

    三道题都是考察最短路算法的判环.其中1860和2240判断正环,3259判断负环. 难度都不大,可以使用Bellman-ford算法,或者SPFA算法.也有用弗洛伊德算法的,笔者还不会SF-_-…… ...

  5. 【POJ】1704 Georgia and Bob(Staircase Nim)

    Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...

  6. 【POJ】1067 取石子游戏(博弈论)

    Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...

  7. POJ 1860 Currency Exchange【bellman_ford判断是否有正环——基础入门】

    链接: http://poj.org/problem?id=1860 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  8. POJ 1860 Currency Exchange【SPFA判环】

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

  9. POJ 1860——Currency Exchange——————【最短路、SPFA判正环】

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

随机推荐

  1. vscode 编写Python走过的坑

    1,在使用vscode 中import turtle 这个模块, 再调用t = turtle.Pen(),始终提示无法找到turtle模块 2.可是使用terminal 中调用turtle模块,没有问 ...

  2. ISA虚拟化的条件

    ISA(Instruction Set Architecture) 指令集体系结构,是硬件与软件层之间的接口. 本地系统虚拟机 本地系统虚拟机,就是Bare-Metal虚拟机,直接运行在硬件上,在它上 ...

  3. 问题1-/usr/bin/python: No module named virtualenvwrapper

    操作系统:Ubuntu 问题:创建虚拟环境时,出现:/usr/bin/python: No module named virtualenvwrapper 解决方法: 1.切换到用户家目录 2.打开隐藏 ...

  4. S1#Python之shebang

    点1 - Python之shebang 一. shebang 在计算机科学中,Shebang是一个由井号和叹号构成的字符串行,其出现在文本文件的第一行的前两个字符. 在文件中存在Shebang的情况下 ...

  5. forEach方法

    *forEach() * -这个方法只支持ie8以上的浏览器 * -forEach方法需要一个函数作为参数 * -像这种函数,由我们创建但是不由我们调用,我们称为回调函数 * 数组中由几个元素函数就会 ...

  6. 笔记:Python列表和元组

    列表 列表和字符串之间的转换 >>> li = list('hello') >>> li ['h', 'e', 'l', 'l', 'o'] >>> ...

  7. python+selenium遍历某一个标签中的内容

    一.python+selenium遍历某一个标签中的内容 举个例子:我要获取列表标签<li></li>的内容 根据python+selenium定位到列表整体,使用for循环获 ...

  8. svg实现绘制路径动画

    1,首先用svg绘制一条path路径,然后进行如下操作 ps: 下面是svg中两个属性及值的意义 stroke-dasharray是让你指定画出的线段每段的长度,第二个值是各段之间空隙的长度. str ...

  9. java zxing 生成条形码和二维吗

    依赖 <dependency> <groupId>com.google.zxing</groupId> <artifactId>core</art ...

  10. springboot启动时过滤不需要注入的类

    在springbootApplication启动类上加入注解 @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterTy ...