【二分答案】Google Code Jam Round 1A 2018

题意:有R个机器人,去买B件商品,有C个收银员,每个收银员有能处理的商品数量上限mi,处理单件商品所需的时间si,以及最后的装袋时间pi。

每个收银员最多只能对应一个机器人,每个机器人也最多只能对应一个收银员。

让你给每个机器人安排他购买的商品数,以及对应哪个机器人,问你最少需要多长时间才能买回所有商品。

二分答案lim,将收银员按照min(m[i],(lim-p[i])/s[i])(此即为该收银员在当前限制下能处理的商品数)从大到小排序,贪心加入,看是否满足即可。

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int T,r,b,c,m[1005],s[1005],p[1005];
int id[1005];
ll lim;
bool cmp(const int &a,const int &b){
	return min((ll)m[a],(lim-(ll)p[a])/(ll)s[a]) > min((ll)m[b],(lim-(ll)p[b])/(ll)s[b]);
}
bool check(){
	ll sum=0;
	sort(id+1,id+c+1,cmp);
	for(int i=1;i<=min(r,c);++i){
		if(lim<(ll)p[id[i]]){
			continue;
		}
		sum+=min((ll)m[id[i]],(lim-(ll)p[id[i]])/(ll)s[id[i]]);
		if(sum>=(ll)b){
			return 1;
		}
	}
	return sum>=(ll)b;
}
int main(){
	//freopen("b.in","r",stdin);
	scanf("%d",&T);
	for(int zu=1;zu<=T;++zu){
		printf("Case #%d: ",zu);
		scanf("%d%d%d",&r,&b,&c);
		for(int i=1;i<=c;++i){
			id[i]=i;
		}
		for(int i=1;i<=c;++i){
			scanf("%d%d%d",&m[i],&s[i],&p[i]);
		}
		ll l=1ll,r=1000000000000000000ll;
		while(l<r){
			lim=(l+r)/2ll;
			if(check()){
				r=lim;
			}
			else{
				l=lim+1ll;
			}
		}
		printf("%lld\n",l);
	}
	return 0;
}

原文地址:https://www.cnblogs.com/autsky-jadek/p/8837137.html

时间: 2024-10-27 16:33:17

【二分答案】Google Code Jam Round 1A 2018的相关文章

Google Code Jam Round 1A 2015 Problem B. Haircut 二分

Problem You are waiting in a long line to get a haircut at a trendy barber shop. The shop has B barbers on duty, and they are numbered 1 through B. It always takes the kth barber exactly Mk minutes to cut a customer's hair, and a barber can only cut

google code jam Round 1A 2015 Problem C. Logging

Problem A certain forest consists of N trees, each of which is inhabited by a squirrel. The boundary of the forest is the convex polygon of smallest area which contains every tree, as if a giant rubber band had been stretched around the outside of th

Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)

Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A wall with a window separates adjacent cells, and

Google Code Jam 2014 Round2

Google Code Jam Round2 晚上10点开始的,开始google一直上不去,然后开了个vpn就行了. 说说我的情况吧. P1就是某年noip普及组纪念品分组,贪心. p2是说给你一个排列,然后每次可以交换两个相邻的数,使得最后序列变为先上升后下降的样子.(n<=1000) 一开始题目看错了,以为是交换任意两个,然后愣了半天不会,去写后两题暴力了. (话说我Round1Cp1题目也看错了害的我逗了好久) 后来突然发现是adjacent elements...(<论英语学习的重要性

Google Code Jam 2012 Practice - Store Credit

Problem You receive a credit C at a local store and would like to buy two items. You first walk through the store and create a list L of all available items. From this list you would like to buy two items that add up to the entire value of the credit

Google Code Jam 2014 Round 2回顾和分析

回顾 比赛开始网络就一直在抽风,不知道宿舍网渣还是有人攻击服务器.刷了n遍n久刷出了题目.提交A小case的时候眼睁睁看着时间过去,却提交不上,这破网.最后A题B题还是解决了,C题扫了一眼,读都没读,就奔D题去了,因为我看到了熟悉的trie这个单词,加之看到小case只有9分,判断小case应该比较容易.前面因为网络浪费了很多时间,加之从未编过trie的程序,只能临时上网翻书去学,最后D小这个可以很容易暴力解的问题也没编完. 最终的rank是13xx,考虑到在这次GCJ之前从未接触过编程竞赛,而

Google Code Jam 2015 Round 1A Haircut 二分

题意:给你每个理发师的理发时间,问你排在队列中的第N个位置,问你应该被哪个理发师剪发. 解题思路:二分时间,看这个时间到第几个人理发了,然后找到临界值,看这个值的时候有那些理发师接待了新旅客的,即可找到那个理发师. 解题代码: 1 // File Name: b.sample.cpp 2 // Author: darkdream 3 // Created Time: 2015年04月18日 星期六 09时05分30秒 4 5 #include<vector> 6 #include<lis

Google Code Jam 2015 Round 1A Mushroom Monster 水

题意:每10秒扫描一下盘子,查看盘子里面的面包个数,问你主角用两种吃法可能吃得的最少的面包. 1)任意吃. 2)每秒以恒定速度. 解题思路:暴力,找差值. 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2015年04月18日 星期六 09时52分04秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #includ

Google Code Jam 2019 Round 1A 题解

A. Alien Rhyme 题意: 思路:将字符反向插入一颗Trie,然后自下而上的贪心即可,即先选后缀长的,再选后缀短的. 实现: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <iomanip> 5 6 #include <vector> 7 #include <cstring> 8 #include <string>