uva 1006 - Fixed Partition Memory Management(完美匹配)
来源:互联网 发布:欧莱雅 妮维雅 知乎 编辑:程序博客网 时间:2024/05/29 16:37
题目链接:uva 1006 - Fixed Partition Memory Management
以任务为X,Y为每个处理器在倒数第几个完成,任务xi连向yj的边权值即为任务xi对处理器的时间贡献值,用KM算法求解。
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int maxn = 55;const int maxm = 505;const int inf = 0x3f3f3f3f;int N, M, A[maxn], V[maxn][maxn], L[maxm];int Lx[maxn], Ly[maxm], W[maxn][maxm];bool S[maxm], T[maxm];int match(int i) {S[i] = true;for (int j = 1; j <= M; j++) {if (Lx[i] + Ly[j] == W[i][j] && !T[j]) {T[j] = true;if (!L[j] || match(L[j])) {L[j] = i;return true;}}}return false;}void update () {int a = inf;for (int i = 1; i <= N; i++) if (S[i]) {for (int j = 1; j <= M; j++) if (!T[j])a = min(a, Lx[i]+Ly[j]-W[i][j]);}for (int i = 1; i <= N; i++)if (S[i]) Lx[i] -= a;for (int i = 1; i <= M; i++)if (T[i]) Ly[i] += a;}void KM () {for (int i = 1; i <= N; i++) {Lx[i] = -inf;for (int j = 1; j <= M; j++) {Lx[i] = max(Lx[i], W[i][j]);}}for (int i = 1; i <= M; i++) L[i] = Ly[i] = 0;for (int i = 1; i <= N; i++) {while (true) {for (int j = 1; j <= M; j++) S[j] = T[j] = 0;if (match(i)) break;else update();}}}void init () {for (int i = 1; i <= M; i++) scanf("%d", &A[i]);int s, t, k;memset(V, inf, sizeof(V));for (int i = 1; i <= N; i++) {scanf("%d", &k);while (k--) {scanf("%d%d", &s, &t);for (int j = 1; j <= M; j++) if (A[j] >= s)V[i][j] = min(V[i][j], t);}}for (int i = 1; i <= N; i++) {for (int j = 1; j <= M; j++) {for (int p = 1; p <= N; p++) {int v = (j-1)*N + p;if (V[i][j] == inf)W[i][v] = -inf;elseW[i][v] = - p * V[i][j];}}}M = M * N;KM();}int main () {int cas = 0;while (scanf("%d%d", &M, &N) == 2 && N + M) {if (cas++) printf("\n");init();printf("Case %d\n", cas);double ans = 0;for (int i = 1; i <= N; i++) ans += Lx[i];for (int i = 1; i <= M; i++) ans += Ly[i];printf("Average turnaround time = %.2lf\n", -ans / N);int P[maxn], RS[maxn], RT[maxn];memset(P, 0, sizeof(P));for (int i = 1; i <= M; i++) {if (L[i]) {int rg = (i-1)/N+1;P[rg] += V[L[i]][rg];RS[L[i]] = rg;RT[L[i]] = P[rg];}}for (int i = 1; i <= N; i++) {int s = P[RS[i]] - RT[i];printf("Program %d runs in region %d from %d to %d\n", i, RS[i], s, s + V[i][RS[i]]);}}return 0;}
0 0
- uva 1006 - Fixed Partition Memory Management(完美匹配)
- UVALive2238 Fixed Partition Memory Management
- UVa1006 - Fixed Partition Memory Management
- UVALive 2238 Fixed Partition Memory Management(建图、KM)
- uvalive 2238 Fixed Partition Memory Management (KM)
- LA 2238 - Fixed Partition Memory Management 二分匹配 World Finals >> 2001
- uva 10615 - Rooks(完美匹配)
- uva 1411 - Ants(几何+完美匹配)
- UVA 1411 - Ants(二分图完美匹配)
- uva 11383 - Golden Tiger Claw(完美匹配)
- uva 1349 - Optimal Bus Route Design(完美匹配)
- Uva 10615 Rooks(二分图完美匹配+补边)
- Memory Management
- Memory Management
- Memory management
- Memory Management
- Memory management
- Memory Management
- 浅谈网络游戏的设计——服务器端编程
- data.table Way - Learning Note Part 1
- 机房收费系统测试计划
- HDU 4117 GRE Words【AC自动机+线段树】
- Android访问百度网站
- uva 1006 - Fixed Partition Memory Management(完美匹配)
- 求两数最大公约数,最小公倍数-Java
- Unity3D 延时执行函数StartCoroutine
- Unity3D基于帧管理器的移动管理器
- Python中运用正则表达式抓取网页图片
- sicily 1051. Biker's Trip Odomete
- 《2016展讯校招软开java笔试题》
- ubuntu 15.10 qt 5 命令行相关注意事项
- iOS_AFNetworking_AFNetworkReachabilityManager(检测网络可达性)