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个积木,最后每个小孩 ...
随机推荐
- VC窗口类的销毁-是否需要delete
Windows窗口如果使用new的方法添加之后,在父窗口析构的时候,有些需要delete有些却不需要delete.这个的确有点坑,由于c++的实现,对于每个自己new的对象,我都会delete删除它, ...
- Ruby开发环境的搭建
1.Ruby的下载 https://rubyinstaller.org/downloads/ 2.Ruby的安装 3.Eclipse配置Ruby开发环境 插件地址:http://rubyeclipse ...
- java攻城狮之路--复习JDBC
1.JDBC中如何获取数据库链接Connection? Driver 是一个接口: 数据库厂商必须提供实现的接口. 能从其中获取数据库连接. 可以通过 Driver 的实现类对象获取数据库连接. 1. ...
- Ubuntu下获取内核源码
查看当前系统使用的内核版本: apt-cache search linux-source 输出如下: linux-source - Linux kernel source with Ubuntu pa ...
- react 父组件给子组件传值
父组件 import React from 'react'import '../page1/header.css'import { Table } from 'antd'import Child fr ...
- codevs2833 奇怪的梦境
2833 奇怪的梦境 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description Aiden陷入了一个奇怪的梦境:他被困 ...
- C++编写谷歌日历
#include<iostream> #include<fstream> using namespace std; void main() //程序从这里开始运行 { int ...
- 46.颜色+品牌下钻分析时按最深层metric进行排序
主要知识点: 在做下钻分析时的排序 需求,以颜色进行bucket,这里bucket里面的doc以其各品牌的平均价格排序, GET /tvs/sales/_search { " ...
- (蓝桥)2017C/C++A组第七题正则问题
#include<iostream> #include<memory.h> #include<stack> #include<string> using ...
- linux获得网卡信息
#define MAX_INTERFACE 64 int showifs() { int i; int rc; int sock; int ifnum; struct ifreq ifr[MAX_IN ...