codeforce626C.Block Towers(二分)
2 seconds
256 megabytes
standard input
standard output
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
9
3 2
8
5 0
10
In the first case, the student using two-block pieces can make a tower of height 2, 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.
第二个样例,应为6可以使2的倍数也可以是3的倍数,所以归为2和3都是可以,这里归为3,因为归为2的话,3就要选择9了
题意:n个人用高度为2的木板,m个人用高度为3的木板堆塔,并且每个人做成的塔的高度不能相同。就是求2的倍数,3的倍数,如果同时是2的倍数和3的倍数,只能属于一个数
分析:二分枚举求解,如果x / 2 < n,x此时一定小于所求值,如果x / 3 < m,x也小于所求值,如果 x / 2 + x / 3 - x / 6 < n + m,也小于所求值,因为n + m是堆成的塔的总个数,他等于长度为2堆成的加上长度为三堆成的减去长度为6堆成(重复只取一次)。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m;
bool judge(int x)
{
if(x / < n || x / < m || x / + x / - x / < m + n)
return ;
return ;
} int main()
{
scanf("%d%d", &n, &m);
int l = ,r = ,mid;
while(r > l)
{
mid = (r + l) / ;
if( judge(mid) )
r = mid; //因为最后就是输出的r,则r一定是满足条件的
else
l = mid + ;
}
printf("%d\n", r);
return ;
}
codeforce626C.Block Towers(二分)的更多相关文章
- Codeforces 626C Block Towers(二分)
C. Block Towers time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...
- 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 ...
- Codeforces 626C Block Towers「贪心」「二分」「数学规律」
题意: 一堆人用方块盖塔,有n个人每次只能加两块方块,有m个人每次只能加三块方块.要求每个人盖的塔的高度都不一样,保证所用方块数最少,求最高的塔的高度. 0<=n+m 0<=n,m< ...
- (二分)Block Towers(cf626)
http://www.codeforces.com/contest/626/problem/C 题意是有一群小朋友在堆房子,现在有n个小孩每次可以放两个积木,m个小孩,每次可以放3个积木,最后每个小孩 ...
- [CF85E] Guard Towers - 二分+二分图
题目描述 In a far away kingdom lives a very greedy king. To defend his land, he built n n n guard towers ...
- 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)
题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...
- Block Towers (思维实现)
个人心得:这题没怎么看,题意难懂.后面比完再看的时候发现很好做但是怎么卡时间是个问题. 题意:就是有m个可以用2层积木的,n个可以用三层积木的,但是他们不允许重复所以可以无限添加. 比如 3 2 一开 ...
- 【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 ...
- CodeForces 626C Block Towers
构造AC的.左右两边都先不用6的倍数,然后哪边数字大那一边往回退一下,然后再比较哪边数字大.......直到结束 #include<cstdio> #include<cstring& ...
随机推荐
- 什么是multipart/form-data请求
根据http/1.1 rfc 2616的协议规定,我们的请求方式只有OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE等,那为为何我们还会有multipart/form-da ...
- cocoaPod相关问题
cocoap简介: 1. 简介 CocoaPods是一个负责管理iOS项目中第三方开源代码的工具,其源码在Github上开源.使用CocoaPods可以节省设置和更新第三方开源库的时间并提高工作效率. ...
- ST3插件——PlainTasks的使用
今天看到一个有意思的ST3插件,可以进行简单的任务管理. 安装很简单:ctrl + shift + p,输入install回车,再输入plaintasks回车即可. 以下是一些支持的操作,更多的操作请 ...
- 【转】【C#】判断两个文件是否相同
使用System.security.Cryptography.HashAlgorithm类为每个文件生成一个哈希码,然后比较两个哈希码是否相同 该哈希算法为一个文件生成一个小的二进制“指纹”,从统计学 ...
- 记录使用gogs,drone搭建自动部署测试环境
使用gogs,drone,docker搭建自动部署测试环境 Gogs是一个使用go语言开发的自助git服务,支持所有平台 Docker是使用go开发的开源容器引擎 Drone是一个基于容器技术的持续集 ...
- matlab取消和添加注释以及一些快捷键
1 matlab中关于注释: 多行注释: 选中要注释的若干语句,工具栏菜单Text->Comment,或者鼠标右击选"Comment",或者快捷键Ctrl+R 取消注释: 选 ...
- 实验一(不知道怎么上传.docx格式)
北京电子科技学院(BESTI) 实 验 报 告 课程:深入理解计算机系统 班级:1353 姓名:魏静静 文艺 刘虹辰 学号:20135302 20135331 20 ...
- win8安装mean.io详解
最近,老大说要安装mean.io,然后……我的win8华丽丽的就上战场了……这期间真是安装得要生要死……最终也终于“不辱使命”成功安装上了…… 废话不多说,进入正题啦 前提当然是电脑有node.环境… ...
- Object-Oriented CSS
1.指导思想: http://oocss.org/ 2.reset.css http://meyerweb.com/eric/tools/css/reset/ 3.normalize.css http ...
- Javascript基础系列之(三)数据类型 (数值 Number)
javascript中想限定一个数的数值,无需限定它是整数还是浮点数型 var num1 = 80 ; var num2 = 55.51; var num3 = -34; var num4 = 9e5 ...