题意:有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. Pool thread stack traces: Thread[C3P0PooledConnectionPoolManager[identityToken->原因解决办法

    今天本地连接测试库测试,发现早上还是好的,下午就崩了,报这个错,使用的是c3po连接池: , 纠结了好久,发现是数据库连接用光了,很多人都在连,果断换了本地库,好使了,看百度说把macPoolSizz ...

  2. perl6: hash小笔记

    > ,,, { => , => } > my $a = :%h h => { => , => } > $a.perl :h({, }) > my ...

  3. 使用postman做接口测试(三)

    三,接口用例的设计 个人感觉用例的设计才是重要的哈,网上查了一些资料总结了一下 1.业务流程测试 通过性验证: 1, 按照接口文档上的参数,正常传参,是否可以返回正确的结果 2, 是否满足前提条件,比 ...

  4. 前端打包工具之fis3的初级使用

    说到打包工具,大家都会想到webpack,我之前也接触过webpack,说实话个人觉得webpack上手容易,但是对于新手来说里面有太多坑,配置文件也不简单.于是乎,我转入了fis3阵营,发现fis3 ...

  5. 下一代Android打包工具,100个渠道包只需要10秒钟 https://github.com/mcxiaoke

    https://github.com/mcxiaoke/packer-ng-plugin https://github.com/Meituan-Dianping/walle https://githu ...

  6. Shell学习笔记:<<EOF子命令

    在shell编程中,“EOF”通常与“<<”结合使用,“<<EOF”表示后续的输入作为子命令或子shell的输入,直到遇到“EOF”,再次返回到主调用shell,可将其理解为分 ...

  7. CVE-2014-1776 秘狐

    传说中的IE秘狐 [CNNVD]Microsoft Internet Explorer 释放后重用漏洞(CNNVD-201404-530) Microsoft Internet Explorer(IE ...

  8. DDD领域模型企业级系统(一)

    领域模型的基本构造块: 1.实体(Entity):有业务生命周期,使用标识进行跟踪. 2.值对象(Value Object):无业务生命周期,用来描述实体. 3.服务(Service):无状态的行为类 ...

  9. Kubernetes Ingress实战

    本节内容: 服务发现与负载均衡 Ingress实战 一.服务发现与负载均衡 在前面的安装部署kubernetes集群中已经简单用示例来演示了Pod和Service,Kubernetes通过Servic ...

  10. Pg188-3 构造方法

    package org.hanqi.array; public class Father { private String name; private int age; public String g ...