8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分

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;
}

转载于:https://www.cnblogs.com/qscqesze/p/5188848.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值