题意:有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. WeX5入门之欢乐捕鱼打包

    一.下载欢乐捕鱼的素材包 https://files.cnblogs.com/files/wordblog/%E7%B4%A0%E6%9D%90.zip 二.把欢乐捕鱼素材放入项目中 并启动tomca ...

  2. Mysql注入root权限直接写一句话马

    首先我们的找到一个有注入的站:这里我用自己搭建的环境表示:大家不要乱来 http://localhost/pentest/sql/sql_injection_get.php?id=1 发现是root权 ...

  3. Spring4笔记1--Spring概述、IoC

    Spring概述: Spring框架: Spring 由 20 多个模块组成,它们可以分为数据访问/集成(Data Access/Integration).Web.面向切面编程(AOP,  Aspec ...

  4. sru源码--language model

    import sys import os import argparse import time import random import math import numpy as np import ...

  5. 已知可生成0~4的rand5(),实现生成0~6的rand7()

    若已知生成0~6的rand7(),求生成0~4的rand5(),则一个方法就是不断生成0~7的数,直到这个数满足0~4就返回. int rand5(){ int res; do{ res = rand ...

  6. python 中的__del__

    # -*- coding: utf-8 -*- # @Time : 2018/9/19 20:21 # @Author : cxa # @File : delDemo.py # @Software: ...

  7. python 结构化数据解析

    # -*- coding: utf-8 -*- # @Time : 2018/8/31 14:32 # @Author : cxa # @File : glomtest.py # @Software: ...

  8. [转]关于MyEclipse下的项目无法使用BASE64Encoder问题的解决办法

    [链接] http://blog.csdn.net/longlonglongchaoshen/article/details/75087616

  9. 数据库-mysql数据类型

    MySQL 数据类型 MySQL中定义数据字段的类型对你数据库的优化是非常重要的. MySQL支持多种类型,大致可以分为三类:数值.日期/时间和字符串(字符)类型. 数值类型 MySQL支持所有标准S ...

  10. MyEclipse自带且常用的快捷键和自己定义的快捷键方法步骤

    1.MyEclipse自带且常用的快捷键 内容提示(补全): Alt+/    导包快捷键: Ctrl+Shift+o    格式化代码: Ctrl+Shift+f    行代码位置上下调换: Alt ...