CodeForces 626C Block Towers(二分)

http://codeforces.com/problemset/problem/626/C

题意:有n个人每次可以放两个积木,m个人,每次可以放3个积木,最后每个人堆得高度都不同,求最大的高度最小是多少;

二分查找这个高度high,这个high满足2的倍数大于等于n,3的倍数大于等于m,high减掉2和3的最小公倍数6的倍数的个数大于等于m+n;

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;

#define N 10003000
#define met(a, b) memset(a, b, sizeof(a))

const double PI = acos(-1.0);

typedef long long LL;

int n, m;

int Search ()
{
    int l = 0, r = N, ans;
    while (l <= r)
    {
        int mid = (l+r)/2;
        if (mid/2>=n && mid/3>=m && mid/2+mid/3-mid/6>=n+m)
            r = mid-1, ans = mid;
        else l = mid+1;
    }
    return ans;
}

int main ()
{
    while (scanf ("%d %d", &n, &m) != EOF)
    {
        int ans = Search ();
        printf ("%d\n", ans);
    }
    return 0;
}


你可能感兴趣的:(CodeForces 626C Block Towers(二分))