【二分答案】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;
}
【二分答案】Google Code Jam Round 1A 2018的更多相关文章
- 【贪心】Google Code Jam Round 1A 2018 Waffle Choppers
题意:给你一个矩阵,有些点是黑的,让你横切h刀,纵切v刀,问你是否能让切出的所有子矩阵的黑点数量相等. 设黑点总数为sum,sum必须能整除(h+1),进而sum/(h+1)必须能整除(v+1). 先 ...
- 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 barb ...
- Google Code Jam Round 1A 2015 解题报告
题目链接:https://code.google.com/codejam/contest/4224486/ Problem A. Mushroom Monster 这题题意就是,有N个时间点,每个时间 ...
- [Google Code Jam (Round 1A 2008) ] A. Minimum Scalar Product
Problem A. Minimum Scalar Product This contest is open for practice. You can try every problem as ...
- Google Code Jam Round 1C 2015 Problem A. Brattleship
Problem You're about to play a simplified "battleship" game with your little brother. The ...
- [Google Code Jam (Qualification Round 2014) ] A. Magic Trick
Problem A. Magic Trick Small input6 points You have solved this input set. Note: To advance to the ...
- [C++]Store Credit——Google Code Jam Qualification Round Africa 2010
Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...
- [C++]Saving the Universe——Google Code Jam Qualification Round 2008
Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...
- Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words
Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...
随机推荐
- tomcat集群及session共享
一般来说,java web app主要用作两个领域: 1.api.api一般是无状态的,所以无需考虑session共享的问题 2.传统web应用和网站,如crm,oa,erp,b2c,bbs等.尤其b ...
- windows 10 部署flask web
起因 本来想这用django 写一个web 应用程序,便于管理mongodb的数据.结果django 不直接支持mongodb……又没时间研究NoSQL.于是想着随便整个api吧…… 于是先用flas ...
- [转]CMake快速入门教程:实战
转自http://blog.csdn.net/ljt20061908/article/details/11736713 0. 前言 一个多月前,由于工程项目的需要,匆匆的学习了一下cmake的使 ...
- Qbot回归,已感染5.4万台计算机
Qbot回归,已感染5.4万台计算机 近日,BAESystems的安全人员发表了一篇关于Qbot网络感知蠕虫回归的调查报告,指出已经感染了5.4万台计算机. FreeBuf百科 Qbot蠕虫,也叫Qa ...
- Spiral Matrix I & II
Spiral Matrix I Given an integer n, generate a square matrix filled with elements from 1 to n^2 in s ...
- Mysql转换成SqlServer数据库,以及SqlServer转换成Mysql数据库
Windows XP sp2 MS SQL Server 2OOO sp1 MySql 5.0.41 1:MSSQLServer数据库导入到MySql数据库 步骤: 1.安装mysql数据库的ODBC ...
- CEC2017 benchmark function调用接口
CEC2017 benchmark function可以从这里下载. 导师最近给了个课题让我自己研究,跟智能优化算法相关的,必不可免的要用到最新的CEC2017 benchmark function, ...
- 分布式git
分布式 Git 你现在拥有了一个远程 Git 版本库,能为所有开发者共享代码提供服务,在一个本地工作流程下,你也已经熟悉 了基本 Git 命令.你现在可以学习如何利用 Git 提供的一些分布式工作流程 ...
- Flask:静态文件&模板(0.1)
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2 前面看了Flask的Quickstart文档,可是,一直没有练习里面的内容,这不,刚刚练习完毕,来写篇博文记录一下! ...
- jenkins主从服务器部署
当服务器为linux系统但也有部分ios代码,此时就需要添加一个从jenkins以便编译ios代码.或者需要多个job同时编译这时就需要搭建主从服务器. 1.主(master)节点安装jenkins ...