LA 4254 Processor (单调队列 + 二分)

185 篇文章 0 订阅
24 篇文章 0 订阅

题意:有n个任务,每个任务有三个参数,ri,di,wi,表示在ri di之内需要执行完工作量为wi的任务,任务可以分块执行,求执行过程中的最大速度的最小值。速度需为整数。


分析:二分判断,判断有些复杂,要用到单调队列,写的挺烂的,但是一遍过了。

#include <queue>
#include <vector> 
#include <cstdio> 
#include <algorithm>
#include <iostream>
#define MAXN 10002
using namespace std;
int n,T;
struct thing
{
	double r,d,w;
} test[MAXN];
bool camp(thing a,thing b)
{
	if(a.r == b.r) return a.d < b.d;
	return a.r < b.r;
}
struct Camp
{
	bool operator() (int a,int b)
	{
		return test[a].d > test[b].d;
	}
};
priority_queue <int,vector<int>,Camp> q;		
bool jud(double v,const thing test[])
{
	thing Test[MAXN];
	for(int i = 1;i <= n;i++) Test[i] = test[i];
	while(!q.empty()) q.pop();
	int now = 1,num = 0;
	q.push(1);
	double pos = Test[1].r;
	while(!q.empty())
	{
		thing &u = Test[q.top()];
		if(u.w/v > u.d - pos) return false;
		double dis = now == n ? u.w/v : min(u.w/v,Test[now+1].r - pos);
		pos += dis;
		u.w -= dis*v;
		if(pos == Test[now+1].r) 
		{
			now++;
			q.push(now);
		}
		if(u.w < 0.000001) 
		{
			q.pop();
			num++;
		}	
		if(q.empty() && num != n) 
		{
			now++;
			pos = Test[now].r;
			q.push(now);
		}
	}
	return true;
}
int main()
{
	cin.sync_with_stdio(false);
	cin>>T;
	while(T--)
	{
		cin>>n;
		for(int i = 1;i <= n;i++)
		 cin>>test[i].r>>test[i].d>>test[i].w;
		sort(test+1,test+1+n,camp);
		int s = 1,t = 10001;
		while(s != t)
		{
			int mid = (s + t) / 2;
			if(jud(mid,test)) t = mid;
			else s = mid + 1;
		}	
		cout<<s<<endl;	
	}	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值