UVA4254 Processor

题意:有n个任务,每个任务有三个参数ri,di和wi,表示必须在时刻[ri,di]之内执行,工作量为wi。处理器执行速度可以变化,当执行速度为s时,工作量为wi。处理器的速度可以变化,当执行速度为s时,一个工作量为wi的任务需要执行wi/s个单位时间。任务不一定连续执行,可以分成若干块。求出处理器执行过程中最大速度的最小值。

首先按照左端点排序,然后二分答案,对于每一刻时间贪心地选当前未结束的任务中右端点最小的那个。

//Serene
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<set>
using namespace std;
const int maxn=1e4+10;
int T,n;

int aa;char cc;
int read() {
	aa=0;cc=getchar();
	while(cc<‘0‘||cc>‘9‘) cc=getchar();
	while(cc>=‘0‘&&cc<=‘9‘) aa=aa*10+cc-‘0‘,cc=getchar();
	return aa;
}

struct Node{
	int l,r,w;
}node[maxn];

bool cmp(const Node& x,const Node& y) {
	return x.l==y.l? x.r<y.r:x.l<y.l;
}

struct Pp{
	int noww,r;
	bool operator < (const Pp& b) const{return r<b.r;}
};

multiset<Pp> G;
multiset<Pp>::iterator it;
bool check(int s) {
	G.clear();
	int pos=1,time=node[1].l,x,y,ss;
	for(;;time++) {
		if(pos>n&&G.empty()) return 1; ss=s;
		while(ss>0&&!G.empty()) {
			it=G.begin(); x=it->noww; y=it->r;
			if(y<time) return 0; G.erase(it);
			if(x>ss) G.insert(Pp{x-ss,y});
			ss-=x;
		}
		while(node[pos].l==time&&pos<=n)
		G.insert(Pp{node[pos].w,node[pos].r}),pos++;
	}
	if(G.empty()) return 1;
	return 0;
}

int main() {
	T=read();
	while(T--) {
		memset(node,0,sizeof(node));
		n=read();int l=0,r=0;
		for(int i=1;i<=n;++i) {
			node[i].l=read();
			node[i].r=read();
			node[i].w=read();
//			l=max(l,(node[i].w-1)/(node[i].r-node[i].l+1));
			r+=node[i].w;
		}
		sort(node+1,node+n+1,cmp);
		while(l<r-1) {
			if(!l) l++;
			int mid=(l+r)>>1;
			if(check(mid)) r=mid;
			else l=mid;
		}
		printf("%d\n",r);
	}
	return 0;
}
/*
1
8
1 6 16
3 5 12
8 15 33
11 14 14
15 18 10
16 19 12
20 24 16
22 25 10
*/

  

时间: 2024-08-02 12:05:33

UVA4254 Processor的相关文章

Processor Speculative &amp; pipeline

Branch-Prediction in a Speculative Dataflow Processor http://cseweb.ucsd.edu/~tullsen/mteac5/kuszmaul.pdf

8.Processor

1.概述 Sink Group允许用户将多个Sink组合成一个实体. Flume Sink Processor 可以通过切换组内Sink用来实现负载均衡的效果,或在一个Sink故障时切换到另一个Sink. sinks – 用空格分隔的Sink集合 processor.type default 类型名称,必须是 default.failover 或 load_balance 2.Default Sink Processor Default Sink Processor 只接受一个 Sink. 不要

Jafka来源分析——Processor

Jafka Acceptor接受client而建立后的连接请求,Acceptor会将Socket连接交给Processor进行处理.Processor通过下面的处理步骤进行client请求的处理: 1. 读取client请求. 2. 依据client请求类型的不同,调用对应的处理函数进行处理. Processor读取client请求是一个比較有意思的事情,须要考虑两个方面的事情:第一,请求规则(Processor须要依照一定的规则进行请求的解析).第二,怎样确定一次请求的读取已经结束(由于是非堵

Inter-partition communication in multi-core processor

A multi-core processor includes logical partitions that have respective processor cores, memory areas, and Ethernet controllers. At least one of the Ethernet controllers is disabled for external communication and is assigned as an inter-partition Eth

Flexible implementation of a system management mode (SMM) in a processor

A?system?management?mode?(SMM) of operating a processor includes only a basic set of hardwired hooks or mechanisms in the processor for supporting SMM. Most of SMM functionality, such as the processing actions performed when entering and exiting SMM,

Method and apparatus for transitioning between instruction sets in a processor

A data processor (104) is described. The data processor (104) is capable of decoding and executing a first instruction (212) of a first instruction set and a second instruction (213-219) in a second instruction set wherein the first instruction (212)

HP Microserver Gen8 Processor FAQ

http://homeservershow.com/forums/index.php?/topic/6596-hp-microserver-gen8-processor-faq/ This guide is a work in progress.  After reading some other people's questions about processors for the Microserver Gen8, including "What's the best choice for

Maintaining processor resources during architectural events

In one embodiment of the present invention, a method includes switching between a first address space and a second address space, determining if the second address space exists in a list of address spaces; and maintaining entries of the first address

PatentTips - Zero voltage processor sleep state

BACKGROUND Embodiments of the invention relate to the field of electronic systems and power management. More particularly, embodiments of the invention relate to a method and apparatus for a zero voltage processor sleep state. As the trend toward adv