/*
题意:有n个任务,给出了每个任务的起始时间和终止时间还有工作量w,处理任务的速度为s时,任务会花费 w / s时间,
然后每个任务都要在规定时间内完成,但任务可以不用连续时间块内完成,要求出让所有时间都顺利完成的最大速度的最小值。
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<algorithm>
using namespace std;
struct node{
int st,en,w;
friend bool operator < (const node &a,const node &b){
return a.en>b.en;
}
};
struct node p[10000+10];
int n;
int cmp(node a,node b){
return a.st < b.st;
}
bool work(int x){
priority_queue <node> q;
int t=1,i=1;
while(1){
while (i<=n && p[i].st<=t)q.push(p[i++]);
int s=x;
while(s!=0 && !q.empty()){
node u=q.top();
q.pop();
int tmp=min(s,u.w);
s-=tmp;
u.w-=tmp;
if(u.w!=0)q.push(u);
}
t++;
if(!q.empty() && q.top().en<=t)return false;
if(q.empty() && i==n+1)return true;
}
}
int main(){
int T;
cin>>T;
while( T-- ){
cin>>n;
int l=0,r=100000;
for (int i = 1; i <= n; i++)scanf("%d%d%d", &p[i].st, &p[i].en, &p[i].w);
sort(p+1,p+n+1,cmp);
while(l<r){
int mid=(l+r)/2;
if(work(mid))r=mid;
else l=mid+1;
}
cout<<l<<endl;
}
return 0;
}LA4254 STL优先队列+二分答案
最新推荐文章于 2026-04-01 02:51:02 发布
本文讨论了如何在不连续的时间块内完成多个任务,以求得完成所有任务的最大速度最小值的问题。通过使用优先队列和二分查找算法,实现了一个高效的解决方案。


1145

被折叠的 条评论
为什么被折叠?



