LA2238 Fixed Partition Memory Management
题目大意:
m(m<=10)个内存区域,n(n<=50)个程序。找出一个方案来,使得平均结束时刻尽量小。题目保证有解。
同一个程序运行在不同大小的内存区域内,其运行时间不同。(注意,这里说的大小是指整个内存区域大小,而不是说:该程序之前有程序运行,占用了一部分内存,剩下的那部分内存大小。。。。。。。)
输入:m和n,然后是m个数表示内存区域大小。再是n行,每行第1个数为情况总数k(k<=10),然后是k对整数s1,t1,s2,t2……sk,tk,满足si<si+1表示在各个内存中的运行时间。
如果内存块总大小s不足s1,则无法在该内存块运行该程序;当si<=s<si+1时,运行时间为ti;当s>=sk时,运行时间为tk
输出:平均最小结束时间和调度方案。
(转自http://blog.csdn.net/u014679804/article/details/46725083)
题解:发现早运行的程序,对后面的结束时刻的影响是固定的,即某个内存区域倒数第p个,贡献为pT,T为程序在某个内存区域的运行时间。于是可以左边为程序,右边为每个内存区域倒数第几个运行,对应连边,边权为贡献,求最小权匹配。不难发现不会出现倒数第一匹配,倒数第二没匹配,倒数第三匹配的情况(何不匹配倒数第二呢?)
拍了很久,平均时间没有错,方案小数据看了很多组也没组
估计是SPJ没有或者不对。。。
网上的程序试了一个,都跟样例输出的一模一样,其他数据也都一模一样。。。
就当是对的吧。。OI一般也不会让输出方案反正。。
#include <cstdio>
#include <cstring>
#define max(a, b) ((a) > (b) ? (a) : (b))
template<class T>
inline void swap(T &a, T &b)
{
T tmp = a;a = b;b = tmp;
}
inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '') c = ch, ch = getchar();
while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
if(c == '-') x = -x;
}
const int INF = 0x3f3f3f3f;
const int MAXN = + ;
const int MAXM = + ;
int size[MAXM * MAXN], s[MAXM * MAXN], t[MAXM * MAXN], n, m, ca;
int g[MAXN][MAXN * MAXM], n1, n2, sla[MAXN * MAXM], pre[MAXN * MAXM], vis[MAXN * MAXM], lab1[MAXN * MAXN], lab2[MAXN * MAXM], lk1[MAXN * MAXN], lk2[MAXN * MAXM];
void cal(int x)
{
memset(vis, , sizeof(vis)), memset(sla, 0x3f, sizeof(sla)), memset(pre, , sizeof(pre)), vis[] = ;
int y;
do
{
y = ;
for(int i = ;i <= n2;++ i)
{
if(vis[i]) continue;
if(lab1[x] + lab2[i] - g[x][i] < sla[i]) sla[i] = lab1[x] + lab2[i] - g[x][i], pre[i] = x;
if(sla[i] < sla[y]) y = i;
}
int d = sla[y];
for(int i = ;i <= n1;++ i) if(vis[lk1[i]]) lab1[i] -= d;
for(int i = ;i <= n2;++ i) if(vis[i]) lab2[i] += d; else sla[i] -= d;
vis[y] = ;
}while(x = lk2[y]);
for(;y;swap(y, lk1[lk2[y] = pre[y]]));
}
double KM()
{
for(int i = ;i <= n1;++ i) cal(i);
int ans = ;
for(int i = ;i <= n1;++ i) ans += g[i][lk1[i]];
return (double)-ans;
}
int tag[MAXN], from[MAXN], to[MAXN], stack[MAXN], tot;
int main()
{ while(scanf("%d %d\n", &m, &n) != EOF && n && m)
{
if(ca) putchar('\n');
memset(from, , sizeof(from)), memset(tag, , sizeof(tag)), memset(to, , sizeof(to)), memset(stack, , sizeof(stack)), n1 = n, n2 = n * m, ++ ca, memset(lab1, -0x3f, sizeof(lab1)), memset(lk1, , sizeof(lk1)), memset(lk2, , sizeof(lk2)), memset(g, -0x3f, sizeof(g)), memset(lab2, , sizeof(lab2));
for(int i = ;i <= m;++ i) read(size[i]);
for(int i = ;i <= n;++ i)//考虑每个程序
{
int k;read(k);
for(int j = ;j <= k;++ j) read(s[j]), read(t[j]);
s[k + ] = INF;
for(int j = ;j <= m;++ j)//在区域j中
for(int l = ;l <= k;++ l)
if(s[l] <= size[j] && size[j] < s[l + ])//运行时间为t[l]
for(int p = ;p <= n;++ p) //倒数第p个运行
g[i][(j - ) * n + p] = - p * t[l], lab1[i] = max(lab1[i], - p * t[l]);
}
printf("Case %d\nAverage turnaround time = %.2lf\n", ca, KM() / (double)n);
for(int i = ;i <= n;++ i) tag[i] = (lk1[i] - ) / n + ;
for(int i = ;i <= m;++ i)
{
tot = ;int sum = ;
for(int j = ;j <= n;++ j) if(tag[j] == i) stack[++ tot] = j;
for(;tot;-- tot)
from[stack[tot]] = sum, to[stack[tot]] = sum = sum + (-g[stack[tot]][lk1[stack[tot]]] / ((lk1[stack[tot]] - ) % n + ));
}
for(int i = ;i <= n;++ i) printf("Program %d runs in region %d from %d to %d\n", i, tag[i], from[i], to[i]);
}
return ;
}
LA2238
LA2238 Fixed Partition Memory Management的更多相关文章
- Fixed Partition Memory Management UVALive - 2238 建图很巧妙 km算法左右顶点个数不等模板以及需要注意的问题 求最小权匹配
/** 题目: Fixed Partition Memory Management UVALive - 2238 链接:https://vjudge.net/problem/UVALive-2238 ...
- UVALive 2238 Fixed Partition Memory Management(二分完美匹配)
题意:计算机中有一些固定大小的内存,内存越大,处理速度越快.对于一个程序,加入不同的内存空间,处理所需时间不同.现给出m个内存空间,n个程序,对于每个程序程序,有k组数据(s,t),分别表示当程序 i ...
- UVALive 2238 Fixed Partition Memory Management 固定分区内存管理(KM算法,变形)
题意:目前有一部分可用内存,分为m个大小固定的区域.现有n个程序要执行,每个程序在不同大小的内存中运行所需的时间不同,要使运行完所有程序所耗时最少,问每个程序在哪块区域中从什么时间运行到什么时间,以及 ...
- Operating System Memory Management、Page Fault Exception、Cache Replacement Strategy Learning、LRU Algorithm
目录 . 引言 . 页表 . 结构化内存管理 . 物理内存的管理 . SLAB分配器 . 处理器高速缓存和TLB控制 . 内存管理的概念 . 内存覆盖与内存交换 . 内存连续分配管理方式 . 内存非连 ...
- Lifetime-Based Memory Management for Distributed Data Processing Systems
Lifetime-Based Memory Management for Distributed Data Processing Systems (Deca:Decompose and Analyze ...
- lwIP Memory Management
http://lwip.wikia.com/wiki/Lwipopts.h Memory management (RAM usage) /** * MEM_LIBC_MALLOC==1: Use ma ...
- Objective -C Memory Management 内存管理 第一部分
Objective -C Memory Management 内存管理 第一部分 Memory management is part of a more general problem in pr ...
- memory management in oracle 11G R2
When we talking about memory management in Oracle, we are refering to SGA and PGA. The management me ...
- [译]C# 7系列,Part 10: Span<T> and universal memory management Span<T>和统一内存管理
原文:https://blogs.msdn.microsoft.com/mazhou/2018/03/25/c-7-series-part-10-spant-and-universal-memory- ...
随机推荐
- 1.1_springboot2.x与缓存原理介绍&使用缓存
一.springboot与缓存介绍&使用缓存 1.JSR107 JAVA Cahing定义了5个核心接口,分别是CachingProvider.CacheManager.Cache.Entry ...
- Stern-Brocot Tree、伪.GCD 副本
Stern-Brocot Tree.伪.GCD 副本 伪.GCD 问题 1:\(f(a,b,c,n) = \sum_{i=0}^{n} [\frac{ai+b}{c}]\) Case 1: \(a\g ...
- Spring 基于xml配置方式的AOP(8)
1.ArithmeticCalculator.java 1 package com.proc; 2 3 public interface ArithmeticCalculator { 4 int ad ...
- SUMMARY | 二分查找
package Search; public class biSearch { //标准的二分查找 public static int stdBiSearch(int[] array,int keyV ...
- spring自定义bean工厂模式解耦
在resources下创建bean.properties accountService=cn.flypig666.service.impl.AccountServiceImpl accountDao= ...
- JavaScript特效源码(3、菜单特效)
1.左键点击显示菜单 左键弹出式菜单[推荐][修改显示的文字及链接即可][共2步] ====1.将以下代码加入HEML的<head></head>之间: <style t ...
- grep 强大的文本搜索工具
1.grep -r "History folder does't exist:" * :中间是要搜索的文本,* 表示全部显示出来
- Tensortflow安装
1. CMD里面 pip install --upgrade --ignore-installed tensorflow
- JS Math.sin() 与 Math.cos() 用法 (含圆上每个点的坐标)
Math.sin(x) x 的正玄值.返回值在 -1.0 到 1.0 之间: Math.cos(x) x 的余弦值.返回的是 -1.0 到 1.0 之间的数: 这两个函数中的X 都是指 ...
- Java-MyBatis-MyBatis3-XML映射文件:insert, update 和 delete
ylbtech-Java-MyBatis-MyBatis3-XML映射文件:insert, update 和 delete 1.返回顶部 1. insert, update 和 delete 数据变更 ...