POJ 1860 Currency Exchange(求环变形)
来源:互联网 发布:隐马尔可夫算法 编辑:程序博客网 时间:2024/06/05 23:48
题意:
。。。
思路:
Bellman-ford判环
//#include<bits/stdc++.h>#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <vector>#include <queue>#include <stack>#include <cassert>#include <algorithm>#include <cmath>#include <set>#include <climits>#include <map>#include <iomanip>using namespace std;#define SPEED_UP iostream::sync_with_stdio(false);#define FIXED_FLOAT cout.setf(ios::fixed, ios::floatfield);#define rep(i, s, t) for(int (i)=(s);(i)<=(t);++(i))#define urep(i, s, t) for(int (i)=(s);(i)>=(t);--(i))#define in_bound(l, r, i) (l)<=(i)&&(i)<(r)#define pb push_backtypedef long long LL;const int inf = INT_MAX/2;const int Maxn = 100;struct Edge{ int from, to; double r, c; Edge() {} Edge(int x, int y, double z, double z2):from(x), to(y), r(z), c(z2){}};int n, m, beg;double d[Maxn+5], S;vector<int> g[Maxn+5];Edge E[1000+5];map<string, int> id;int go () { rep(i, 1, n) d[i] = 0; d[beg] = S; rep (k, 1, n) { rep(i, 1, 2*m) { Edge &e = E[i]; if ( (d[e.from]-e.c) * e.r > d[e.to]) { //cout << "to " << e.to << " : " << (d[e.from]-e.c) * e.r << endl; if (k == n) return 1; d[e.to] = (d[e.from]-e.c) * e.r; } } } return 0;}int solve() { return go();}int main() {#ifndef ONLINE_JUDGE freopen("input.in", "r", stdin);#endif SPEED_UP cin >> n >> m >> beg >> S; int A, B; double rAB, cAB, rBA, cBA; rep(i, 1, m) { cin >> A >> B >> rAB >> cAB >> rBA >> cBA; E[i] = Edge(A, B, rAB, cAB); E[i+m] = Edge(B, A, rBA, cBA); } if (solve()) cout << "YES\n"; else cout << "NO\n"; return 0;}
0 0
- POJ 1860 Currency Exchange(求环变形)
- POJ 1860 Currency Exchange(bellman变形)
- (Bellman_ford+队列 求环) poj 1860 Currency Exchange
- POJ 1860 Currency Exchange(BellmanFord求递增环)
- POJ 1860 Currency Exchange Bellma求有无环 .
- poj 1860 Currency Exchange (最短路变形-spfa)
- poj 1860 Currency Exchange(BellmanFord算法的变形,求正环)
- POJ 1860 Currency Exchange(BellmanFord算法的变形,求正环)
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- Poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- POJ 1860 Currency Exchange
- Google Picasa API初体验
- BZOJ2705 Longge的问题
- Codeforces Round #292 (Div. 2)
- android之Notification通知
- php反射获取类和方法中的注释
- POJ 1860 Currency Exchange(求环变形)
- 一次读取文本文件的所有内容到std::string
- go语言的工作空间和GOPATH环境变量
- Eclipse Java注释模板设置详解
- Delegate与NSNotification区别
- 【ACM之旅】那就从这里起航吧!
- 【Uva 1585】 Score
- codevs2492 上帝造题的七分钟2 BZOJ3211 花神游历各国
- 解决ERROR 1130 (HY000): Host '192.168.1.9' is not allowed to connect to this MySQL server