CodeForces--626C--Block Towers (二分)
| Time Limit: 2000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
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
1 3
9
3 2
8
5 0
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 (二分)的更多相关文章
- Codeforces 626C Block Towers(二分)
C. Block Towers time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...
- Codeforces 626C Block Towers「贪心」「二分」「数学规律」
题意: 一堆人用方块盖塔,有n个人每次只能加两块方块,有m个人每次只能加三块方块.要求每个人盖的塔的高度都不一样,保证所用方块数最少,求最高的塔的高度. 0<=n+m 0<=n,m< ...
- CodeForces 626C Block Towers
构造AC的.左右两边都先不用6的倍数,然后哪边数字大那一边往回退一下,然后再比较哪边数字大.......直到结束 #include<cstdio> #include<cstring& ...
- 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 ...
- codeforce626C.Block Towers(二分)
C. Block Towers time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces 626C
...
- CodeForces - 327D Block Tower
D. Block Tower time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- [Codeforces 1199C]MP3(离散化+二分答案)
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...
- 【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 ...
- (二分)Block Towers(cf626)
http://www.codeforces.com/contest/626/problem/C 题意是有一群小朋友在堆房子,现在有n个小孩每次可以放两个积木,m个小孩,每次可以放3个积木,最后每个小孩 ...
随机推荐
- Android Studio查看CPU使用率。
进入AS自带的CMD,依次输入: (1)进入Android Atudio安卓的目录: 1.H: 2.cd AndroidStudio\sdk\platform-tools (2)adb shell ( ...
- java攻城师之路--复习java web之request_respone
Servlet技术 两条主线1.HTTP协议 2.Servlet生命周期 init() 方法中参数 ServletConfig 对象使用通过ServletConfig 获得 ServletContex ...
- 海盗(Haidao)网店系统最新官方版
产品介绍:经过开发团队半个月的努力,Haidao v1.1 beta版终于和大家见面了,在这个版本中我们重点系统目录结构和整体框架进行了改进,同时新增加了多个功能模块. 四大功能模块意在打造最灵活的电 ...
- MyEclipse中VSS的使用详解
本文系转载,原文地址http://hi.baidu.com/yi88cheng/blog/item/13dd862f765e6b5c4fc226e5.html
- 6、scala Map和Tuple
1. 创建Map 2.访问Map元素 3.修改Map元素的值 4.遍历Map 5.SortedMap和LinkedHashMap 6.Map的元素类型Tuple 1. 创建Map 创建不可变的Ma ...
- [问题记录]-技术学习-RocketMQ-全球集群部署问题
一:问题场景 公司在部署全球的RocketMQ的时候,遇到亚洲区的服务器往欧洲区的RocketMQ发送消息失败的情况. 总共有出现两个问题 1:No Topic Route Info org.apac ...
- Tomcat8 连接池
1.所有的tomcat项目共用一个连接池配置 1.1 修改conf->context.xml文件,在Context节点下配置 <Resource name="jdbc/myDat ...
- js 滚动条
<script type="text/javascript"> //文档高度1016 包含隐藏的margin和padding 实际1000 //文档1000 //窗口高 ...
- kvm virt-install 使用小结
简介: virt-install 能够为KVM.Xen或其它支持libvrit API的hypervisor创建虚拟机并完成GuestOS安装. 此外,它能够基于串行控制台.VNC或SDL支持文本或图 ...
- Oracle开发常用函数 max 最大数 自动加 1 的模式
create sequence bs_com_seq increment by 1 start with 1 minvalue 1 maxvalue 999999 cycle nocache orde ...