Codeforces--626C--Block Towers

51 篇文章 0 订阅

题目描述:
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.
输入描述:
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.
输出描述:
Print a single integer, denoting the minimum possible height of the tallest tower.
输入:
1 3
3 2
5 0
输出:
9
8
10
题意:
n+m个人用积木搭堆(每个人搭一堆),n个人只能用高度为2的积木, m个人只能用高度为3的积木。两种积木均有无限多个。

这些人都不希望自己搭出的堆的高度与其他任何人的相同。请找出在所有人搭出的积木高度都不同的情况下,这些人中搭出的最高的堆的高度最小值。
题解
简单贪心
代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF){
        int two = 2 * n;
        int three = 3 * m;
        for(int i = 6; i <= min(two,three); i += 6){
            if(two <= three){
                two += 2;
            }
            else three += 3;
        }
        printf("%d\n",max(two,three));
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值