C. Block Towers

题目连接:

http://www.codeforces.com/contest/626/problem/C

Description

Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.

The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

Input

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Output

Print a single integer, denoting the minimum possible height of the tallest tower.

Sample Input

1 3

Sample Output

9

Hint

题意

有n个人在用2的倍数,有m个人在用3的倍数,所有人的数都要求不一样

你要使得最大数最小,然后问你这个答案是多少

题解:

我感觉贪心要挂……

所以直接瞎暴力二分就好了,check是O(1)的

我们讨论一下2的倍数,3的倍数,6的倍数就好了

代码

#include<bits/stdc++.h>
using namespace std;
int n,m;
bool check(int k)
{
int num1 = k/2;
int num2 = k/3;
int num3 = k/6;
if(n>num1)return false;
if(m>num2)return false;
int d = min(num1-n,num3);
if(d+(num2-num3)<m)return false;
return true;
}
int main()
{
scanf("%d%d",&n,&m);
int l = 0,r = 1e7;
int ans = 0;
while(l<=r)
{
int mid = (l+r)/2;
if(check(mid))r=mid-1,ans=mid;
else l=mid+1;
}
cout<<ans<<endl;
}

8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分的更多相关文章

  1. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  2. 8VC Venture Cup 2016 - Elimination Round

    在家补补题   模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...

  3. 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

    D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...

  4. codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

    C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...

  5. 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题

    F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...

  6. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  7. 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp

    F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...

  8. 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分

    E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...

  9. 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞

    B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...

随机推荐

  1. JS中,children和childNodes的不同之处

    <ul id="ul"><li></li><li></li><li><span></spa ...

  2. MFC不同工程(解决方案)之间对话框资源的复制与重用方法(转)

    原文转自 https://blog.csdn.net/lihui126/article/details/45556687

  3. Linux Platform驱动模型(二) _驱动方法【转】

    转自:http://www.cnblogs.com/xiaojiang1025/archive/2017/02/06/6367910.html 在Linux设备树语法详解和Linux Platform ...

  4. Sqlserver获取所有数据库名,表信息,字段信息,主键信息,以及表结构等。

    --获取所有数据库名: SELECT name FROM master..sysdatabases WHERE name NOT IN ( 'master', 'model', 'msdb', 'te ...

  5. 安装icephp 记

    下面开始安装: 一:yum 安装 首先需要添加一个yum源. # vi /etc/yum.repos.d/zeroc-ice-amzn.repo写入: [zeroc-ice]name=Ice 5 fo ...

  6. sicily 1012. Stacking Cylinders & 1206. Stacking Cylinders

    Time Limit: 1sec    Memory Limit:32MB  Description Cylinders (e.g. oil drums) (of radius 1 foot) are ...

  7. sicily 1063. Who's the Boss

    Time Limit: 1sec    Memory Limit:32MB  Description Several surveys indicate that the taller you are, ...

  8. Python抓取学院新闻报告

    Python案例 scrapy抓取学院新闻报告 任务 抓取四川大学公共管理学院官网(http://ggglxy.scu.edu.cn)所有的新闻咨询. 实验流程 1.确定抓取目标.2.制定抓取规则.3 ...

  9. [ python ] 类中的一些特殊方法

    item系列 __getitem__(self, item) 对象通过 object[key] 触发 __setitem__(self, key, value) 对象通过 object[key] = ...

  10. POJ 2912 Rochambeau(种类并查集+枚举)

    题目链接:http://poj.org/problem?id=2912 题目大意:n个人玩,玩石头剪刀布游戏,其中1人是裁判,剩下的n-1个人分为3组, 他们商量好了,相同组的人每次都出相同的手势,不 ...