kuangbin_ShortPath E (POJ 1860)
第一次做判环 然后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)的更多相关文章
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- poj 1860 Currency Exchange (SPFA、正权回路 bellman-ford)
链接:poj 1860 题意:给定n中货币.以及它们之间的税率.A货币转化为B货币的公式为 B=(V-Cab)*Rab,当中V为A的货币量, 求货币S通过若干此转换,再转换为原本的货币时是否会添加 分 ...
- POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...
- POJ 1860——Currency Exchange——————【最短路、SPFA判正环】
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- poj - 1860 Currency Exchange Bellman-Ford 判断正环
Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...
- POJ 1860 Currency Exchange (Bellman-Ford)
题目链接:POJ 1860 Description Several currency exchange points are working in our city. Let us suppose t ...
- POJ 1860(spfa)
http://poj.org/problem?id=1860 题意:汇率转换,与之前的2240有点类似,不同的是那个题它去换钱的时候,是不需要手续费的,这个题是需要手续费的,这是个很大的不同. 思路: ...
- POJ 1860 Currency Exchange 最短路 难度:0
http://poj.org/problem?id=1860 #include <cstdio> //#include <queue> //#include <deque ...
随机推荐
- a Makefile
obj-m += showpid.o obj-m += ps.o all: make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) mo ...
- C++ primer的第一章的主要内容
第一章主要是把C++的主要的部分简单的介绍了一下,让读者对C++开始有一个简单的了解.看完第一章的收获就是知道如何去读入不确定数目的输入,主要是形式是:whlie(cin>>s){},利用 ...
- HYSBZ 1858 线段树 区间合并
//Accepted 14560 KB 1532 ms //线段树 区间合并 /* 0 a b 把[a, b]区间内的所有数全变成0 1 a b 把[a, b]区间内的所有数全变成1 2 a b 把[ ...
- LIST 和 MAP
Collection和Map LIST 集合 arraylist arraylist源代码: 1.ArrayList 底层采用数组实现,当使用不带参数的构造方法生成 ArrayList 对象时,实际上 ...
- win10 mac地址修改器
NoVirus Thanks MAC Address Changer NoVirus Thanks MAC Address Changer is yet another simple MAC addr ...
- 一段显示隐藏列表HTML代码
一段显示隐藏列表HTML代码, 技巧在于把页面上的元素(“返回首页”)和控制显示/隐藏的元素(id=navs-menu)放在一个共同的div上,并在该div上绑定onmouseover和onmouse ...
- 《view programming guide for iOS 》之可以使用动画效果的属性
frame—Use this to animate position and size changes for the view. ,框架,可以视图动态改变大小和位置 bounds—Use this ...
- 在VS2010 中兼容Qt4和Qt5
1,同时安装Qt4和Qt5 Qt_add,然后在 2. 如果之前的项目使用Qt4编写的,如果新添加新的类和ui的话,一定要选择Qt Add_in 1.1.11,不然就无法生成moc文件,随便选择 Ch ...
- Python的交互式界面 编写 .
from tkinter import * # 导入tkinter模块的所有内容 root = Tk() # 创建一个文本Label对象 textLabel = Label(root, # 将内容绑定 ...
- How to set up a basic working Appium test environment
Appium is a test framework targeting devices; although it is very handy and powerful, it is not so s ...