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个积木,最后每个小孩 ...
 
随机推荐
- Python爬取贴吧中的图片
			
#看到贴吧大佬在发图,准备盗一下 #只是爬取一个帖子中的图片 1.先新建一个scrapy项目 scrapy startproject TuBaEx 2.新建一个爬虫 scrapy genspider ...
 - python 之 sqlite3
			
# -*- coding: utf-8 -*- ''' 创建数据库日志,三列为时间 身份证号和备注名''' import os import sys import sqlite3 import dat ...
 - Prime算法生成最小生成树
			
虽说是生成树,但我只将生成的边输出了.至于怎么用这些边来创建树...我不知道_(:з」∠)_ //Prime方法生成最小生成树 void GraphAdjacencyListWeight::Gener ...
 - 关于python中的staticmethod
			
python中的staticmethod 主要是方便将外部函数集成到类体中,美化代码结构,重点在不需要类实例化的情况下调用方法 如果你去掉staticmethod,在方法中加self也可以通过实例化访 ...
 - accmcolor
			
accmcolor c; c.setcolorindex(1); playertablerecord.setcolor(c);
 - 谈一谈a:link、a:visited、a:hover、a:active的正确使用顺序
			
前端路上,未来还远,所以基础部分必须扎实,走好现在脚下的每一步才是现在最重要的. 下面进入正题吧. 1. <a>标签 我们先说一说<a>标签是干啥用的. <a> 标 ...
 - JavaFX桌面应用开发-鼠标事件和键盘事件
			
鼠标相关事件的操作初始代码 package application; import javafx.application.Application;import javafx.event.ActionE ...
 - time模块和datatime模块
			
一.time模块 time.time() 获取时间戳 time.sleep() 睡几秒 time.gmtime() utc时间元组 time.localtime() 本地时间元组 time.mktim ...
 - POJ-2135-Farm Tour(最大费用最小流)模板
			
Farm Tour POJ - 2135 When FJ's friends visit him on the farm, he likes to show them around. His farm ...
 - C++实现双人枪战游戏
			
//单机版枪战游戏,喜欢就拿走,把赞留下//by floatiy #include<iostream> #include<cstdio> #include<windows ...