POJ 3469 Dual Core CPU 最小割
来源:互联网 发布:中国移动宽带拨号软件 编辑:程序博客网 时间:2024/05/16 19:41
题意:给你一个双核处理器 再给你n个进程在这两个处理器上的处理时间 但是这些进程需要相互交换信息 给你m行信息u v c 分别代表如果u v进程不在同一个处理器交换信息 则要花费额外的时间c 问你运行完这n个进程的最小时间花费
思路:对于一个事物有两个状态的 一般要用到二分图或者最小割来解决 这题就是最小割 建图方法是 对于进程i在两个处理器的花费时间a b 分别建图S到i 容量为b 代表如果想让i属于T集合 则要花费b来割断这条边 然后建图i到T 容量为a 意义相似 然后对于限制条件u v c 分别建图u到v v到u 容量均为c 代表如果想要u v 不属于容易个集合 则要花费c来割断这条边 然后跑最大流即可
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;#define REP( i, a, b ) for( int i = a; i < b; i++ )#define FOR( i, a, b ) for( int i = a; i <= b; i++ )#define CLR( a, x ) memset( a, x, sizeof a )#define CPY( a, x ) memcpy( a, x, sizeof a )#define BUG puts( "*****BUG****" )typedef long long LL;const int maxn = 20000 + 10;const int maxe = 1000000 + 10;const int inf = 1e9;struct Edge{ int v, c, f; int next; Edge() {} Edge(int v, int c, int f, int next) : v(v), c(c), f(f), next(next) {}};struct ISAP{ int n, s, t; int num[maxn], cur[maxn], d[maxn], p[maxn]; int Head[maxn], cntE; int Q[maxn], head, tail; Edge edge[maxe]; void Init(int n){ this -> n = n; cntE = 0; CLR(Head, -1); } void Add(int u, int v, int c){ edge[cntE] = Edge(v, c, 0, Head[u]); Head[u] = cntE++; edge[cntE] = Edge(u, 0, 0, Head[v]); Head[v] = cntE++; } void Bfs(){ CLR(d, -1); CLR(num, 0); d[t] = 0; head = tail = 0; Q[tail++] = t; num[0] = 1; while(head != tail){ int u = Q[head++]; for(int i = Head[u]; ~i; i = edge[i].next){ Edge &e = edge[i]; if(~d[e.v]) continue; d[e.v] = d[u] + 1; Q[tail++] = e.v; num[d[e.v]] ++; } } } int Maxflow(int s, int t){ this -> s = s; this -> t = t; CPY(cur, Head); Bfs(); int u = p[s] = s, flow = 0; while(d[s] < n){ if(u == t){ int f = inf, neck; for(int i = s; i != t; i = edge[cur[i]].v){ if(f > edge[cur[i]].c - edge[cur[i]].f){ f = edge[cur[i]].c - edge[cur[i]].f; neck = i; } } for(int i = s; i != t; i = edge[cur[i]].v){ edge[cur[i]].f += f; edge[cur[i]^1].f -= f; } flow += f; u = neck; } int ok = 0; for(int i = cur[u]; ~i; i = edge[i].next){ Edge &e = edge[i]; if(e.c > e.f && d[e.v] + 1 == d[u]){ ok = 1; cur[u] = i; p[e.v] = u; u = e.v; break; } } if(!ok){ int m = n - 1; if(--num[d[u]] == 0) break; for(int i = Head[u]; ~i; i = edge[i].next){ Edge &e = edge[i]; if(e.c - e.f > 0 && m > d[e.v]){ cur[u] = i; m = d[e.v]; } } ++num[d[u] = m + 1]; u = p[u]; } } return flow; }}solver;int n, m;void solve(){ int S = 0, T = n + 1; solver.Init(T + 1); FOR(i, 1, n){ int a, b; scanf("%d%d", &a, &b); solver.Add(S, i, b); solver.Add(i, T, a); } REP(i, 0, m){ int u, v, d; scanf("%d%d%d", &u, &v, &d); solver.Add(u, v, d); solver.Add(v, u, d); } printf("%d\n", solver.Maxflow(S, T));}int main(){ //freopen("in.txt", "r", stdin); while(~scanf("%d%d", &n, &m)) solve(); return 0;}
0 0
- POJ 3469 Dual Core CPU //最小割
- POJ 3469 Dual Core CPU(最小割)
- poj 3469 Dual Core CPU 最小割
- 【POJ 3469】 Dual Core CPU --最小割
- POJ 3469 Dual Core CPU | 最小割
- POJ 3469 Dual Core CPU 最小割
- 【最小割】POJ-3469 Dual Core CPU
- poj 3469 Dual Core CPU 最小割
- POJ 3469 Dual Core CPU 最小割
- POJ 3469 --Dual Core CPU【最小割】
- POJ 3469 Dual Core CPU(最小割)
- poj 3469 Dual Core CPU(最小割)
- POJ 3469 Dual Core CPU(最小割)
- poj 3469 Dual Core CPU (最小割模型)
- poj 3469 Dual Core CPU (最小割->最大流)
- poj 3469 Dual Core CPU(最小割)
- POJ 3469 Dual Core CPU 最小割入门题
- POJ 3469 Dual Core CPU(最小割)
- 我的第一个博客
- Training:Hash及应用
- 反射的应用
- javascript基础学习之-事件冒泡
- 通过id查询用户,但是只返回指定的字段
- POJ 3469 Dual Core CPU 最小割
- PopoverController for iPhone
- 第十四周项目3-OOP版电子词典
- uva 264 Count on Cantor
- TCP/IP协议族-----6、IP分组的交付和转发
- 测试数据真假难辨-IT精英自我思考
- CentOS安装zip unzip命令
- Android EditText控件切换可编辑状态
- Mysql连接池解决并发问题