【差分约束】 HDOJ 1534 Schedule Problem
来源:互联网 发布:vb下载官方 编辑:程序博客网 时间:2024/05/11 23:31
不难的差分约束。。列出四类不等式,建好图就可以了。。。
#include <iostream> #include <queue> #include <stack> #include <map> #include <set> #include <bitset> #include <cstdio> #include <algorithm> #include <cstring> #include <climits> #include <cstdlib>#include <cmath>#include <time.h>#define maxn 100005#define maxm 300005#define eps 1e-10#define mod 998244353#define INF 999999999#define lowbit(x) (x&(-x))#define mp mark_pair#define ls o<<1#define rs o<<1 | 1#define lson o<<1, L, mid #define rson o<<1 | 1, mid+1, R typedef long long LL;//typedef int LL;using namespace std;LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}void scanf(int &__x){__x=0;char __ch=getchar();while(__ch==' '||__ch=='\n')__ch=getchar();while(__ch>='0'&&__ch<='9')__x=__x*10+__ch-'0',__ch = getchar();}// headint inq[maxn], outq[maxn], dis[maxn], t[maxn];int h[maxn], next[maxm], v[maxm], cost[maxm];queue<int> q;char ss[maxn];int cnt, n, m;void init(void){memset(h, -1, sizeof h);memset(inq, 0, sizeof inq);memset(outq, 0, sizeof outq);for(int i = 0; i <= n; i++) dis[i] = -INF;}void read(void){for(int i = 1; i <= n; i++) scanf(t[i]);}bool spfa(int s){while(!q.empty()) q.pop();dis[s] = 0, q.push(s), inq[s] = 1;while(!q.empty()) {int u = q.front(); q.pop(), inq[u] = 0, outq[u]++;if(outq[u] > n+1) return false;for(int e = h[u]; ~e; e = next[e])if(dis[u] + cost[e] > dis[v[e]]) {dis[v[e]] = dis[u] + cost[e];if(!inq[v[e]]) q.push(v[e]), inq[v[e]] = 1;}}return true;}void addedges(int u, int vv, int c){next[cnt] = h[u], h[u] = cnt, v[cnt] = vv, cost[cnt] = c, cnt++;}void work(void){int a, b;while(scanf("%s", ss), ss[0] != '#') {//scanf("%d%d", &a, &b);scanf(a), scanf(b);if(ss[0] == 'S' && ss[2] == 'S') addedges(b, a, 0);if(ss[0] == 'S' && ss[2] == 'F') addedges(b, a, t[b]);if(ss[0] == 'F' && ss[2] == 'S') addedges(b, a, -t[a]);if(ss[0] == 'F' && ss[2] == 'F') addedges(b, a, t[b] - t[a]);}for(int i = 1; i <= n; i++) addedges(0, i, 0);}int main(void){int _ = 0;while(scanf("%d", &n), n != 0) {read();init();work();printf("Case %d:\n", ++_);if(!spfa(0)) printf("impossible\n");else for(int i = 1; i <= n; i++) printf("%d %d\n", i, dis[i]);printf("\n");}return 0;}
0 0
- 【差分约束】 HDOJ 1534 Schedule Problem
- HDOJ 1534 Schedule Problem 差分约束
- HDU--1534[Schedule Problem] 差分约束
- HDU 1534 Schedule Problem 差分约束
- HDU 1534 Schedule Problem 差分约束
- 【HDU】1534 Schedule Problem 差分约束
- hdoj 1534 Schedule Problem 【差分约束】【SPFA求最长路】
- HDU 1534 Schedule Problem 差分约束输出一组解
- HDU 1534 Schedule Problem(差分约束系统)
- 杭电1534 Schedule Problem(差分约束)
- HDU 1534 Schedule Problem(差分约束)
- HDU 1534 Schedule Problem 最短路+差分约束
- Schedule Problem (HDU 1534 差分约束+SPFA)
- hud-1534 Schedule Problem(差分约束)
- Schedule Problem 【ZJU1455】 差分约束
- hdu1534 Schedule Problem (spfa差分约束)
- HDU1534 Schedule Problem 【差分约束系统】
- HDU1534 Schedule Problem【SPFA】【差分约束】
- i++和i--运算符优先级
- ACM [NOIP1999] 回文数(水模拟)
- HDU 1372 Knight Moves BFS求马走的最短路径
- 慕司板V1注意事项及问题汇总
- CSU - 1256 天朝的单行道
- 【差分约束】 HDOJ 1534 Schedule Problem
- 深入理解C++面向对象机制(二)虚继承
- c语言自定义方法实现字符串的7个操作
- Longest Substring Without Repeating Characters
- 双目视觉的嵌入式移植遇到问题了,两个摄像头不能同时打开
- C++ static、const和static const类型成员变量声明以及初始化
- 《windows游戏编程大师技巧》第五章:DirectX基础知识和令人生畏的COM
- 【java swing 编程】文件替换小秘书(一)
- inline构造函数的问题