第一次做判环 然后RE了五次 死在了奇怪的点

memset(vis, 0, sizeof dis);

memset(dis, 0, sizeof vis);

什么鬼?? 什么鬼??

其实代码本身还是不难的 就是spfa另外开个数组记录入队次数

spfa不用写cmp真是太好了 operator什么的真的搞不清

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#define INF 0x3F3F3F3F
using namespace std; struct Node{
double c;//commission
double r;//rate
int point;
int next;
}node[];
int size, head[];
int n, m, s;
double sq; void add(int from, int to, double rate, double commission)
{
node[size].r = rate;
node[size].c = commission;
node[size].point = to;
node[size].next = head[from];
head[from] = size++;
}
bool spfa()
{
double dis[];
int count[];
bool vis[];
memset(count, , sizeof count);
memset(dis, , sizeof dis);
memset(vis, false, sizeof vis); queue<int> q;
q.push(s);
dis[s] = sq;
vis[s] = true;
while(!q.empty()){
int u = q.front();
q.pop();
vis[u] = false;
for(int i = head[u]; ~i; i = node[i].next){
int j = node[i].point;
if(dis[j] < (dis[u] - node[i].c) * node[i].r){
dis[j] = (dis[u] - node[i].c) * node[i].r;
if(!vis[j]){
q.push(j);
vis[j] = true;
count[j]++;
if(count[j] > n) return true;
}
}
}
}
return false;
}
int main()
{
while(~scanf("%d%d%d%lf", &n, &m, &s, &sq)){
size = ;
memset(head, -, sizeof head);
while(m--){
int from, to;
double r1, c1, r2, c2;
scanf("%d%d%lf%lf%lf%lf", &from, &to, &r1, &c1, &r2, &c2);
add(from, to, r1, c1);
add(to, from, r2, c2);
}
if(spfa()) puts("YES");
else puts("NO");
}
return ;
}

kuangbin_ShortPath E (POJ 1860)的更多相关文章

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

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

  2. POJ 1860 Currency Exchange (最短路)

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

  3. poj 1860 Currency Exchange (SPFA、正权回路 bellman-ford)

    链接:poj 1860 题意:给定n中货币.以及它们之间的税率.A货币转化为B货币的公式为 B=(V-Cab)*Rab,当中V为A的货币量, 求货币S通过若干此转换,再转换为原本的货币时是否会添加 分 ...

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

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

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

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

  6. poj - 1860 Currency Exchange Bellman-Ford 判断正环

    Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...

  7. POJ 1860 Currency Exchange (Bellman-Ford)

    题目链接:POJ 1860 Description Several currency exchange points are working in our city. Let us suppose t ...

  8. POJ 1860(spfa)

    http://poj.org/problem?id=1860 题意:汇率转换,与之前的2240有点类似,不同的是那个题它去换钱的时候,是不需要手续费的,这个题是需要手续费的,这是个很大的不同. 思路: ...

  9. POJ 1860 Currency Exchange 最短路 难度:0

    http://poj.org/problem?id=1860 #include <cstdio> //#include <queue> //#include <deque ...

随机推荐

  1. JAVA 打印九九乘法表

    /** *  * @author liangxiaoyu * @version 1.0 *2015-09-18 */public class JJ { public static void main( ...

  2. Python单元测试——unittest

    unittest是python自带的一个模块 python344\Lib\unittest 官方参考文档: http://docs.python.org/2.7/library/unittest.ht ...

  3. hdu3033 分组背包

    //Accepted 896 KB 156 ms //http://blog.csdn.net/juststeps/article/details/8712150 //dp[i][l]=max(dp[ ...

  4. Python学习路程day4

    迭代器&生成器 迭代器 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退,不过这也没什么,因为人们很少在迭代途中往后退. ...

  5. 一道面试题:按照其描述要求用java语言实现快速排序

    回来想了想,写出了如下的程序: /** * 一道面试题,按照其描述要求进行快速排序(英文的,希望理解是对的..) * 要求:和一般的快速排序算法不同的是,它不是依次交换pivot和左右元素节点(交换2 ...

  6. 未来WEB程序员

    作为一名程序员,如果你想在这个领域内继续向前进步或者在当前的经济形势下保持不被炒鱿鱼,那么你就决不应当自满自足,你需要继续学习.近日,著名IT评论员Justin James在他的博客中列出了未来五年程 ...

  7. KeySweeper 微软无线键盘嗅探装置

    Author:Samy Kamkar From: http://samy.pl/keysweeper/ 中文字幕由Galaxy无名提供 PS:视频传到youku之后发现50秒左右的字幕被干掉了,不知道 ...

  8. 事件委托 EventHandler

    事件就是当对象或类状态发生改变时,对象或类发出的信息或通知.发出信息的对象或类称为"事件源",对事件进行处理的方法称为"接收者",通常事件源在发出状态改变信息时 ...

  9. Emacs常用命令

    1.离开Emacs 挂起Emacs C-z 退出Emacs C-x C-c 2.文件 打开文件 C-x C-f 保存文件 C-x C-s 保存所有的文件 C-x s 将一个文件的内容插入到当前buff ...

  10. __set()与__get() 魔术方法

    在面向对象编程的过程中,对于类当中的各个成员变量,都有不同的访问属性,比如公有的(public)属性,在类内部和类外部都可直接调用:而私有的(private)和受保护的(protected),在类外不 ...