题意:有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的更多相关文章

  1. 【贪心】Google Code Jam Round 1A 2018 Waffle Choppers

    题意:给你一个矩阵,有些点是黑的,让你横切h刀,纵切v刀,问你是否能让切出的所有子矩阵的黑点数量相等. 设黑点总数为sum,sum必须能整除(h+1),进而sum/(h+1)必须能整除(v+1). 先 ...

  2. 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 ...

  3. Google Code Jam Round 1A 2015 解题报告

    题目链接:https://code.google.com/codejam/contest/4224486/ Problem A. Mushroom Monster 这题题意就是,有N个时间点,每个时间 ...

  4. [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 ...

  5. Google Code Jam Round 1C 2015 Problem A. Brattleship

    Problem You're about to play a simplified "battleship" game with your little brother. The ...

  6. [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 ...

  7. [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 ...

  8. [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 ...

  9. 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 ...

随机推荐

  1. beego项目运行过程

    一:首先man.go,整个程序的入口 func main() { beego.Run() } 然后beego.run()代码 // Run beego application. // beego.Ru ...

  2. 20165320 预备作业3 :Linux安装及命令入门

    一.VirtualBox与Linux的安装 我是按照老师给的链接下的最新版本的VirtualBox5.26,然后Ubuntu软件(版本是16.04,最新的是17)是自己在网上找的旧版本下好的,因为我在 ...

  3. Python使用OpenCV实现简单的人脸检测

    文章目录: OpenCV安装 安装numpy 安装opencv OpenCV使用 OpenCV测试 效果图: 注意: 图片人脸检测 程序要求: 技术实现思路 注意 本文使用的环境是:Windows+P ...

  4. tomcat发布html静态页面

    一.环境 在Linux系统安装JDK并配置环境变量,安装tomcat(在tomcat官网下载压缩包即可,我使用的是tomcat7 https://tomcat.apache.org/download- ...

  5. FPGA quartus开发中常见的错误处理

    1.Warning: An incorrect timescale is selected for the Verilog Output (.VO) file of this PLL design. ...

  6. 去除TFS版本控制

    对于曾经做过TFS版本控制的项目,在版本控制服务不可用的时候,依然会在每次打开项目的时候都提示:当前项目是版本控制的项目,但是当前版本控制不可用,balabala的信息,如果是需要进行版本控制的项目在 ...

  7. Python3 item系列

    一.前言 #在python中一切皆对象 ''' 创建了一个dict实例-->dic就是dict的实例对象 我们通过dic['k1']可以得到k1所对应的值 那么我们自定义一个类,可不可以使用对象 ...

  8. 20165333 预备作业3 Linux安装及学习

    预备作业3 Linux安装及学习 Linux系统安装 在老师的教程帮助下成功的完成了虚拟机的安装,但安装过程中也遇到了一些问题.在下载ubuntu时,总是下载失败,在求助同学后,在中文版官网的网址,才 ...

  9. hdu 5137 去掉一个点 使得最短路最大(2014广州现场赛 K题)

    题意:从2~n-1这几个点中任意去掉一个点,使得从1到n的最短路径最大,如果任意去掉一个点1~n无通路输出Inf. Sample Input4 51 2 31 3 71 4 502 3 43 4 23 ...

  10. #Git 详细中文安装教程

    Step 1 Information 信息 Please read the following important information before continuing 继续之前,请阅读以下重要 ...