省选专练之神仙贪心IOI2013Robert

19 篇文章 0 订阅
8 篇文章 0 订阅

【问题描述】 小沐把玩具扔在地板上,乱七八糟。庆幸的是,有一种特殊的机器人可以收拾玩具。不过他需要 确定哪个机器人去拣哪个玩具。 一共有 T 个玩具,整数 w[i]表示这个玩具的重量,整数 s[i]表示这个玩具的体积。机器人有 两种,分别是:弱机器人和小机器人。

◆有 A 个弱机器人。每个弱机器人有一个重量限制 X[i],它只能拿起重量严格小于 x[i]的玩 具,与玩具的体积大小没有关系。

◆有 B 个小机器人。每个小机器人有一个体积限制 Y[i],它只能拿起体积严格小于 Y[i]的玩 具,与玩具的重量大小没有关系。 每个

机器人用 1 分钟将一个玩具拿走放好。不同的机器人可以同时拿走并放好不同的玩具。 你的任务是确定机器人是否可以将所有玩具都收拾好,如果是,那么最少用多少时间可以收拾好。

Marita's little brother has left toys all over the living room floor! Fortunately, Marita has developed special robots to clean up the toys. She needs your help to determine which robots should pick up which toys. There are T toys, each with an integer weight W[i] and an integer size S[i] . Robots come in two kinds: weak and small.

There are A weak robots. Each weak robot has a weight limit X[i] , and can carry any toy of weight strictly less than X[i] . The size of the toy does not matter.

There are B small robots. Each small robot has a size limit Y[i] , and can carry any toy of size strictly less than Y[i] . The weight of the toy does not matter.

Each of Marita's robots takes one minute to put each toy away. Different robots can put away different toys at the same time. Your task is to determine whether Marita's robots can put all the toys away, and if so, the shortest time in which they can do this.

这居然不是IOI的签到题(Day2-T5)

神仙贪心。

明显发现答案成一个单调的情况

二分答案

如何贪心:先对询问以重量关键字排序

对weak再按照尽可能取体积大的原则取走

对于剩下small的按照尽可能取体积大的原则取走

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef int INT;
#define int long long
const int N=1e6+10;
struct Node{
	int x,y;
}S[N],tmp[N];
int X[N];
int Y[N];
int T,A,B;
priority_queue<Node> Q;
bool cmp(Node A,Node B){
	return A.x<B.x;
}
bool cmp2(int A,int B){
	return A>B;
}
bool operator < (Node A,Node B){
	return A.y<B.y;
}
bool check(int sum){
	while(!Q.empty())Q.pop();
	int now=1;
	for(int i=1;i<=A;++i){
		while(S[now].x<X[i]&&now<=T)Q.push(S[now]),++now;
		for(int j=1;!Q.empty()&&j<=sum;++j)Q.pop();
	}
	while(now<=T)Q.push(S[now]),++now;
	for(int i=1;i<=B;i++){
		for(int j=1;j<=sum&&!Q.empty()&&Q.top().y<Y[i];++j)Q.pop();
	}
	if(!Q.empty())return 0;
	return 1;
}
INT main(){
//	freopen("test.in","r",stdin);
	scanf("%lld%lld%lld",&A,&B,&T);
	for(int i=1;i<=A;++i)scanf("%lld",&X[i]);
	sort(X+1,X+1+A);
	for(int i=1;i<=B;++i)scanf("%lld",&Y[i]);
	sort(Y+1,Y+1+B,cmp2);
	for(int i=1;i<=T;++i){
		scanf("%lld%lld",&S[i].x,&S[i].y);
	}
	sort(S+1,S+1+T,cmp);
	int l=1;
	int r=T+1;
	int ans=-1;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid)){
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	cout<<ans;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值