zoukankan      html  css  js  c++  java
  • CF626C Block Towers

    链接:https://www.luogu.org/problemnew/show/CF626C

    题目描述

    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. nn of the students use pieces made of two blocks and mm 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.

    输入输出格式

    输入格式:

    The first line of the input contains two space-separated integers nn and mm ( 0<=n,m<=10000000<=n,m<=1000000 , $ n+m&gt;0 $ ) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

    输出格式:

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

    输入输出样例

    输入样例#1: 复制
    1 3
    
    输出样例#1: 复制
    9
    
    输入样例#2: 复制
    3 2
    
    输出样例#2: 复制
    8
    
    输入样例#3: 复制
    5 0
    
    输出样例#3: 复制
    10
    

    说明

    In the first case, the student using two-block pieces can make a tower of height 44 , and the students using three-block pieces can make towers of height 33 , 66 , and 99 blocks. The tallest tower has a height of 99 blocks.

    In the second case, the students can make towers of heights 22 , 44 , and 88 with two-block pieces and towers of heights 33 and 66 with three-block pieces, for a maximum height of 88 blocks.

    题意:

    给两个数字n,m。
    • 求构造出n 个2 的倍数,m 个3 的倍数,数
    字各不相同,求最大值的最小值。

    题解:

    最大值最小or 最小值最大
    • 首先确定题目能否用二分思想:
    • 1. 是否满足单调性.
    • 2. 是否有可行的判断条件。
    • 对于这道题,简单判断来看,对应出的“构造出n 个2 的倍数,
    m 个3 的倍数”这个解都有多个,而解集中有一个最小的,就是
    答案,而下一个解集对应的最小值,又比这个答案大。
    • 所以答案是单调递增。满足单调性

    #include<bits/stdc++.h>
    using namespace std;
    
    const double eps = 1e-6;
    int n, m;
    bool check(int x){
        int num1 = x/2, num2 = x/3, num3 = x/6;
        if(num1 < n || num2 < m)return 0;
        if(num1 + num2 - num3 < n + m) return 0;
        return 1;
        
    }
    int main(){
        cin>>n>>m;
        int lf = 0, ans, rg = 2000000000;
        while(lf <= rg){
            int mid = (lf + rg) >> 1;
            if(check(mid))rg = mid - 1, ans = mid;
            else lf = mid + 1;
        } 
        printf("%d
    ", ans);
    }
    View Code
  • 相关阅读:
    bzoj 4237 稻草人
    bzoj 4537 最小公倍数
    POJ 2763 Housewife Wind(树链剖分)(线段树单点修改)
    HDU 3966 Aragorn's Story(树链剖分)(线段树区间修改)
    spoj 913 Query on a tree II (倍增lca)
    spoj 375 Query on a tree (树链剖分)
    hiho一下第133周 2-SAT·hihoCoder音乐节(2-SAT)(强连通)
    hiho一下第131周 后缀自动机二·重复旋律8(循环相似子串)
    hiho一下第130周 后缀自动机二·重复旋律7
    hiho一下第129周 后缀自动机二·重复旋律6
  • 原文地址:https://www.cnblogs.com/EdSheeran/p/9277874.html
Copyright © 2011-2022 走看看