第一次做判环 然后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. SharePoint开发 - 自定义导航菜单(三)附其他代码

    博客地址 http://blog.csdn.net/foxdave 接上篇点击打开链接 LeftNavGroupTemplate.cs internal class LeftNavGroupTempl ...

  2. Queryable.GroupBy<TSource, TKey> 方法 (IQueryable<TSource>, Expression<Func<TSource, TKey>>) 转

    根据指定的键选择器函数对序列中的元素进行分组. 命名空间:  System.Linq程序集:  System.Core(在 System.Core.dll 中) 语法 C# C++ F# VB   p ...

  3. poj2104 线段树 划分树

    学习:http://www.cnblogs.com/pony1993/archive/2012/07/17/2594544.html 划分树的build: 划分树是分层构建的,在构建的t层时,我们可以 ...

  4. mysql 为某一数据库下所有表中添加相同字段

    BEGIN  DECLARE s_tablename VARCHAR(100);  /*显示表的数据库中的所有表 SELECT table_name FROM information_schema.t ...

  5. PHP中使用mysql处理结果集

    一.从结果集中将记录取出    mysql_fetch_row($result); 从结果集中取得一行作为枚举数组 mysql_fetch_row($result mysql_fetch_assoc( ...

  6. PHP中目录的操作

    文件的操作:创建文件,删除文件,重命名文件rename(),移动/复制文件,读取,大小(PHP都有内置的函数) 目录的操作:创建目录(有),删除目录,复制目录,统计目录大小,遍历(自己定义函数) 一. ...

  7. HDU 5862(离散化+树状数组)

    Problem Counting Intersections 题目大意 给定n条水平或竖直的线段,统计所有线段的交点个数. (n<=100000) 解题分析 首先将线段离散化. 然后将所有线段按 ...

  8. Inno如何在安装完成时删除指定的文件夹(下的所有文件及子目录)??

    删除安装目录下的任意文件夹及下的所有文件及子目录,或者删除指定目录的文件夹,要如何做到呢?谢谢!! //删除文件    用 DeleteFile 只能删除一个文件,不能使用通配符来删除多个文件Dele ...

  9. SqlSever2005 一千万条以上记录分页数据库优化经验总结

    http://www.cnblogs.com/jirigala/archive/2010/11/03/1868011.html 待测试???

  10. C++学习笔记15:操作符重载的函数原型列表(推荐)

    //普通四则运算 friend A operator +(const A & lhs, const A & rhs); friend A operator -(const A & ...