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& ...
随机推荐
- U3D Debug.log的问题
今天在测试有yield有关的问题时,发现Debug.log()是异步输出机制.不一定会在调用后立即执行. 在C++有类似问题:std::cout 也不一定会立即输出,加上"\n"或 ...
- IBatis.net介绍
IBatis.net介绍 IBatis.net 是2001年发起的开源项目,它是一个轻量级的ORM框架,现在IBatisNET已经是属于Apache下的一个子项目了,最新版本是1.6.2. 官方网站: ...
- Asp.Net MVC 4 Web API 中的安全认证-使用OAuth
各种语言实现的oauth认证: http://oauth.net/code/ 上一篇文章介绍了如何使用基本的http认证来实现asp.net web api的跨平台安全认证. 这里说明一个如何使用oa ...
- Android调用蓝牙打印机
首先需要一个jar包,bluesdk,请自行百度. 具体排版样式跟网络打印机打印排版样式实现一样,这里不多叙述,只贴一个实现方法代码.蓝牙打印机使用前需要先跟手机配对,可以保存在本地,记录下地址,这里 ...
- 一道c语言运算符优先级问题
一道c语言运算符优先级问题 #include <iostream> using namespace std; int main() { char test[] = {"This ...
- [CareerCup] 2.2 Kth to Last Element of Linked List 链表的倒数第k个元素
2.2 Implement an algorithm to find the kth to last element of a singly linked list. 这道题让我们求链表中倒数第k个元 ...
- 点击事件touches与ios的手势UIGestureRecognizer
.h文件 @property (weak,nonatomic) IBOutlet UILabel *messageLabel;@property (weak,nonatomic) IBOutlet U ...
- Windows Phone & Windows App应用程序崩溃crash信息抓取方法
最近有用户反馈,应用有崩溃的情况,可是本地调试却无法重现问题,理所当然的,我想到了微软的开发者仪表盘,可以查看一段时间内的carsh记录,不过仪表盘生成carsh记录不是实时的,而且生成的报告查看非常 ...
- mysql查询所有表行数
SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'DATABASE_NAME' ;
- Java并发编程-CopyOnWriteArrayList
CopyOnWriteArrayList原理 首先每次写操作,都将数组copy一份,并赋值给arrays 读操作读不加锁 写操作加锁 ReentrantLock 因为每次写都要copy数组,这是一项繁 ...