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 ...
随机推荐
- touch ImageView
package com.example.touchdemo; import android.os.Bundle;import android.app.Activity;import android.u ...
- matlab调用opencv函数的配置
环境: VS2010 活动解决方案平台x64 WIN 8.1 Opencv 2.4.3 Matlab 2012a 1. 首先保证vs2010能正确调用opencv函数, 2. Matlab中选择编 ...
- 元素ID命名规范
因为本框架默认所有内容都位于一个Document中,所以为元素命名为ID的时候需要做到唯一性,如果确实不可避免的会出现有重读ID的现象,需要操作当前页片(页面片段,就是子页面)的时候,尽量用: $.C ...
- JS创建自定义对象
普通对象的创建: 创建对象: 1.people = new Object(); people.name = "lin"; people.age = "26“; 2.创建字 ...
- poj3667 线段树 区间合并
//Accepted 3728 KB 1079 ms //线段树 区间合并 #include <cstdio> #include <cstring> #include < ...
- App跳转至系统Settings
很多著名和非著名的App有在App内通过某种方式跳转到系统Settings的功能.不论初心和交互,某认为这个功能用的好确实是很方便的,Control Center功能有限,Home键点击起来很累,至于 ...
- ajax 请求超过了5s 还没有返回 的话 就自动取消
ajax请求时有个参数可以借鉴一下 var ajaxTimeOut = $.ajax({ url:'', //请求的URL timeout : 1000, //超时时间设置,单位毫秒 type : ' ...
- unity3d打包和包的使用
打包: ①Assets下新建文件夹Editor和steamingAssets ②对选定文件打包: using UnityEngine; using UnityEditor; using System. ...
- php大力力 [028节] 如何下载js文件,网上一个*.js无法下载啊??????
php大力力 [028节] 如何下载js文件,网上一个*.js无法下载啊?????? safari也无法下载 迅雷也无法下载 是不是对方网站服务器的不让下载那个js目录的文件??? 只能调用js函数啊 ...
- 实现:编辑短信,按power键锁屏后,再点亮屏幕,进入的还是编辑短信界面,按返回键才会进入解锁界面。
描述:在编辑短信界面按电源键锁屏后,重新按电源键点亮屏幕,并没有进入到锁屏界面而是在编辑短信界面,此时短信界面悬浮与锁屏界面之上,这时按返回键关闭编辑短信界面,回到锁屏界面,是如何实现的呢,只需要在需 ...