中医药院校程序设计竞赛备赛一-Problem H: Block Towers(题意理解)

题目解释看红字 

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.(1.n个学生以两块砖头为一个单元叠砖,m个学生以3块砖头为一个单元叠砖)

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.(2.n + m个学生使用的砖块总数没有相同的) Find the minimum height necessary for the tallest of the students' towers.(3.找到某一种叠法,使它能够成为所有n + m个学生叠的砖块总最高的那一个使用的砖块数记为Max,因为Max可以很大很大,所以只要稍高于第二高的砖块就好,所以求的是满足最大高度时的最小值)

Input

 The first line of the input contains two space-separated integers n and m (0≤n,m≤1000000, 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

 In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.

 测试样例解释:

1个学生以两块砖头为一个单元叠砖(这个学生叠的砖块高度可以是2、4、6、8、10...只要没有重复的高度就行),3个学生以3块砖头为一个单元叠砖(每个学生叠的高度可以是3、6、9、12、15...,只要没有重复的高度就行),因为要求一个最大高度h,并且h是最大高度里的最小值,所以3个学生以3块砖头为一个单元叠砖(每个学生叠的高度这里取3、6、9),1个学生以两块砖头为一个单元叠砖(这里取2、4、8,都行),所以满足条件的最小高度是9。

因为每逢6数字就相同,题目要求高度要唯一,所以要减去。

参考博主链接,感谢~

【通过代码】

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
    int a, b;
    while(scanf("%d%d",&a,&b) != EOF)
    {
        for(int i = 0 ; ;i ++)
        {
            if(i / 2 >= a && i /3 >= b && i / 2 + i / 3 -i / 6 >= a + b)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
    
    return 0;
}

猜你喜欢

转载自blog.csdn.net/hzyhfxt/article/details/82762591