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 ...
随机推荐
- C语言中输入输出函数
1.1.1 格式化输入输出函数Turbo C2.0 标准库提供了两个控制台格式化输入. 输出函数printf() 和scanf(), 这两个函数可以在标准输入输出设备上以各种不同的格式读写数据.pri ...
- greenDao 3.0基础
引入greenDao3.0 首先在project的gradle文件中引入greenDAO插件 dependencies { classpath 'com.android.tools.bui ...
- char 数组和 int 之间转化
上周工作结束,来到斯凯网络也将近半个月来. 没有新人的感念,最多的是将自己当作一个战士. 废话不多说,直接入正题,在没有仔细考虑问题之前我们总会 觉得:这尼玛的有毛线难度啊,不就是一个 int 转为c ...
- kali linux karmetasploit配置
原理分析:http://www.freebuf.com/articles/77055.html 转官方说明:https://www.offensive-security.com/metasploit- ...
- vega prime 1.2 (视景仿真)
Vega Prime 1.2 (视景仿真) MPI的视景仿真渲染工具Vega是世界上领先的应用于实时视景仿真.声音仿真和虚拟现实等领域的软件环境,它用来渲染战场仿真.娱乐.城市仿真.训练模拟器和计算可 ...
- Ubuntu 14.10 下安装Synergy,不同电脑之间公用一套键盘鼠标
因为工作时候有多台电脑放在一起,如果每个用一套键盘鼠标很是不方便,所以希望能够不用电脑之间公用一套键盘鼠标. Synergy可以实现不同电脑之间公用一套键盘鼠标,并且支持简单的复制粘贴.很好用. 它还 ...
- hdu 2058
PS:TLE了N次...虽然结果对了...后来看了公式才知道要枚举项数才行... 代码: #include "stdio.h"#include "math.h" ...
- Day1 summary
对比了几篇在hadoop环境中实现关联规则.频繁项集的论文,文章结构都涉及mapreduce模型.传统与改进apriori算法比较.实验结果分析(数据规模-用时or加速比,节点-用时or加速比).有一 ...
- Ubuntu系统启用Apache Mod_rewrite模块
在终端中执行 sudo a2enmod rewrite 指令后,即启用了 Mod_rewrite 模块. 另外,也可以通过将 /etc/apache2/mods-available/rewrite.l ...
- Postfix之sasldb2
# 2.#配置postfix启用sasldb2作为smtp的账号秘密效验方式 3.#编辑通过sasl启用smtp账号密码效验的配置 4.vi /etc/sasl2/smtpd.conf #vi写入或编 ...