Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit
Status

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

Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10

Sample Output

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.

In the second case, the students can make towers of heights
2, 4, and 8 with two-block pieces and towers of heights
3 and 6 with three-block pieces, for a maximum height of
8 blocks.

n个人使用2米长的材料,m个人使用3米长的材料,材料数量不限,每个人都建自己的塔,但是塔的高度不能有一样的,问最大高度的最小值

因为是2米跟3米的材料,所以公倍数含6的会有重复,这个是重点

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int judge(int x)
{
if(x/2<n||x/3<m||x/2+x/3-x/6<m+n)
return 0;
return 1;
}
int main()
{
cin>>n>>m;
int l=0,r=10000000,mid;
while(l<r)
{
mid=(l+r)/2;
if(judge(mid))
r=mid;
else
l=mid+1;
}
cout<<r<<endl;
return 0;
}

CodeForces--626C--Block Towers (二分)的更多相关文章

  1. Codeforces 626C Block Towers(二分)

    C. Block Towers time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...

  2. Codeforces 626C Block Towers「贪心」「二分」「数学规律」

    题意: 一堆人用方块盖塔,有n个人每次只能加两块方块,有m个人每次只能加三块方块.要求每个人盖的塔的高度都不一样,保证所用方块数最少,求最高的塔的高度. 0<=n+m  0<=n,m< ...

  3. CodeForces 626C Block Towers

    构造AC的.左右两边都先不用6的倍数,然后哪边数字大那一边往回退一下,然后再比较哪边数字大.......直到结束 #include<cstdio> #include<cstring& ...

  4. 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分

    C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...

  5. codeforce626C.Block Towers(二分)

    C. Block Towers time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. Codeforces 626C

                                                                                                        ...

  7. CodeForces - 327D Block Tower

    D. Block Tower time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  8. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  9. 【CodeForces 626C】Block Towers

    题意 给你n,m,如果 n个2的倍数和m个3的倍数,这n+m个数各不相同,那么求最大的数的最小值. 分析 方法1:枚举最大值为i,直到 i/2+i/3-i/6(不重复的2或3的倍数)≥n+m,并且要i ...

  10. (二分)Block Towers(cf626)

    http://www.codeforces.com/contest/626/problem/C 题意是有一群小朋友在堆房子,现在有n个小孩每次可以放两个积木,m个小孩,每次可以放3个积木,最后每个小孩 ...

随机推荐

  1. 离线安装Selenium

    https://blog.csdn.net/poem_ruru/article/details/79032140

  2. ats 与 https

    一些证书相关的描述:   https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKe ...

  3. FusionCharts 更新 chart data 数据

    var AlarmChart = null; function alarmChartReBuild(totalNum, alarmNum) { var alarmPart = (alarmNum * ...

  4. CPU重要性能参数

    内容来自http://www.360doc.com/content/18/1124/15/60810319_796935567.shtml CPU有几个重要的参数:主频.核心.线程.缓存.架构.那么他 ...

  5. 学习csv

    1.csv文件读取,csv文件是常用的数据存储格式之一,我们使用Python模块来处理csv文件,这是一个天气信息表 import csv from matplotlib import pyplot ...

  6. zabbix--TCP状态监控

    Tcp的连接状态对于我们web服务器来说是至关重要的,尤其是并发量ESTAB:或者是syn_recv值,假如这个值比较大的话我们可以认为是不是受到了攻击(例如SYN攻击),或是是time_wait值比 ...

  7. Centos7搭建ansible运维自动化工具

    1)设置主机名和hosts文件 2)配置阿里云repo源 Wget -O /etc/yum.repos.d/aliyun.repo https://mirrors.aliyun.com/repo/Ce ...

  8. python包与模块

    Python基础-包与模块 摘要 为重用以及更好的维护代码,Python使用了模块与包:一个Python文件就是一个模块,包是组织模块的特殊目录(包含__init__.py文件). 模块搜索路径,Py ...

  9. 使用官方组件下载图片,保存到MySQL数据库,保存到MongoDB数据库

    需要学习的地方,使用官方组件下载图片的用法,保存item到MySQL数据库 需要提前创建好MySQL数据库,根据item.py文件中的字段信息创建相应的数据表 1.items.py文件 from sc ...

  10. 35.分组聚合操作—bucket+metric

    主要知识点: bucket+metric 计算分种颜色的电视的平均价格     语法: GET /tvs/sales/_search { "size" : 0, "agg ...