心累,陕西邀请赛学校不支持,可能要自费了。。

思路:套用Bellman-Ford判断负环的思路,把大于改成小于即可判定是否存在从源点能到达的正环。如果存在正环,那么完全多跑几次正环就可以把钱增加到足够返回到S并且大于原来的金额。

AC代码

#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 200 + 5;
int u[maxn], v[maxn];
double r[maxn], c[maxn];
double d[maxn];
bool bell(double st, int s, int n, int m) {
	for(int i = 0; i < n; ++i) d[i] = -inf;
	d[s] = st;
	for(int i = 0; i < n-1; ++i)
		for(int j = 0; j < m; ++j) {
			int x = u[j], y = v[j];
			if(d[x] > -inf) d[y] = max(d[y], (d[x] - c[j])*r[j]);
		}
	for(int i = 0; i < m; ++i) {
		int x = u[i], y = v[i];
		if(d[y] < (d[x] - c[i])*r[i] && d[x] > -inf) return true; //存在正环
	}
	return false;
}
int main() {
	int n, m, s;
	double V;
	while(scanf("%d%d%d%lf", &n, &m, &s, &V) == 4) {
		int cur = 0;
		for(int i = 0; i < m; ++i) {
			scanf("%d%d", &u[cur], &v[cur]);
			scanf("%lf%lf", &r[cur], &c[cur]);
			++cur;
			u[cur] = v[cur-1], v[cur] = u[cur-1];
			scanf("%lf%lf", &r[cur], &c[cur]);
			++cur;
		}
		if(bell(V, s, n, cur)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

如有不当之处欢迎指出!

POJ - 1860 Bellman-Ford判正环的更多相关文章

  1. POJ 2240 Arbitrage (Bellman Ford判正环)

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:27167   Accepted: 11440 Descri ...

  2. poj1860 兑换货币(bellman ford判断正环)

    传送门:点击打开链接 题目大意:一个城市有n种货币,m个货币交换点,你有v的钱,每个交换点只能交换两种货币,(A换B或者B换A),每一次交换都有独特的汇率和手续费,问你存不存在一种换法使原来的钱更多. ...

  3. POJ 2240 Arbitrage spfa 判正环

    d[i]代表从起点出发可以获得最多的钱数,松弛是d[v]=r*d[u],求最长路,看有没有正环 然后这题输入有毒,千万别用cin 因为是大输入,组数比较多,然后找字符串用strcmp就好,千万不要用m ...

  4. Currency Exchange POJ - 1860 (spfa判断正环)

    Several currency exchange points are working in our city. Let us suppose that each point specializes ...

  5. POJ 2240 Arbitrage(判正环)

    http://poj.org/problem?id=2240 题意:货币兑换,判断最否是否能获利. 思路:又是货币兑换题,Belloman-ford和floyd算法都可以的. #include< ...

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

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

  7. poj 1860 bellman 求正环

    #include<stdio.h> #include<string.h> #include<queue>//只需判断是否有正环路径就可以了 using namesp ...

  8. POJ 3621 Sightseeing Cows 【01分数规划+spfa判正环】

    题目链接:http://poj.org/problem?id=3621 Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total ...

  9. poj1860(spfa判正环)

    题目连接:http://poj.org/problem?id=1860 题意:有多种从a到b的汇率,在你汇钱的过程中还需要支付手续费,那么你所得的钱是 money=(nowmoney-手续费)*rat ...

随机推荐

  1. python_5_模块

    创:5_4_2017 修: 什么是模块? --标准库+第三方库+自定义,为实现某一方面的功能集合(变量,函数,类) 如何安装第三方库? --pip install 第三方库 如何导入和使用模块? -- ...

  2. redis五大类型用法

    Redis五大类型:字符串(String).哈希/散列/字典(Hash).列表(List).集合(Set).有序集合(sorted set)五种Controller:@Resource RedisTe ...

  3. 比较Maven和Ant

    从今天开始,整理maven一系列. Maven 它是什么? 如何回答这个问题要看你怎么看这个问题. 绝大部分Maven用户都称Maven是一个"构建工具":一个用来把源代码构建成可 ...

  4. 用powershell实现:“倩女幽魂姥姥”版《语音报警系统》

    ------[第一章 前言]------ win7,及以上版本中,是自带语音库的,系统自带一套女声中文库,一套女声英文库.用powershell调用,从而发音,制作报警系统.是一件太简单的事情,只需要 ...

  5. css层叠样式初学

    一.css简介 1.层叠样式表:叠加效果,不同css对同一html修饰,冲突部分,优先级高作用,不冲突部分,共同作用 2.css作用 (1)修饰html (2)替代了标签自身的颜色,字号等属性,提高复 ...

  6. bzoj 2627: JZPKIL [伯努利数 Pollard-rho]

    2627: JZPKIL 题意:求 \[ \sum_{i=1}^n (n,i)^x [i,n]^y,\ [i,n] = lcm(i,n) \] \(n \le 10^{18},\ x,y\le 300 ...

  7. hdu 4656 Evaluation [任意模数fft trick]

    hdu 4656 Evaluation 题意:给出\(n,b,c,d,f(x) = \sum_{i=1}^{n-1} a_ix^i\),求\(f(b\cdot c^{2k}+d):0\le k < ...

  8. BZOJ 1061: [Noi2008]志愿者招募 [单纯形法]

    传送门 题意: 长为$n$的序列,第$i$位至少$b_i$,$m$种区间使$[l_i,r_i]+1$代价为$a_i$ 求满足的最小花费 复习单纯形法重做一遍 原始问题$m$个变量$n$个约束,$a_{ ...

  9. 【linux之bash】

    bash的发展 1974年 贝尔实验室 Bourne Bourne Shell --> Bsh.sh 1978年 berke bill jey C shell --> Csh tcsh 8 ...

  10. javamail+ical4j发送会议提醒

    本篇讲述小编在使用ical4j时对其的理解与使用,留作笔记的同时希望能帮助到大家! 初学者可以先了解下ical4j的基本信息: iCalender编程基础,了解与使用ical4j:https://ww ...