zoukankan      html  css  js  c++  java
  • 8VC Venture Cup 2016

    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;
    }
  • 相关阅读:
    sklearn之线性回归
    机器学习概述
    scipy之定积分计算和简单图像处理
    scipy之插值器
    numpy之排序
    spring mvc 实现文件上传
    Maven安装本地jar包到本地仓库
    spring mvc实现转发和重定向
    sprign mvc 解决中文乱码问题
    spring mvc 中使用session
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5188848.html
Copyright © 2011-2022 走看看