8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分
C. Block Towers
题目连接:
http://www.codeforces.com/contest/626/problem/C
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
Sample Output
9
Hint
题意
有n个人在用2的倍数,有m个人在用3的倍数,所有人的数都要求不一样
你要使得最大数最小,然后问你这个答案是多少
题解:
我感觉贪心要挂……
所以直接瞎暴力二分就好了,check是O(1)的
我们讨论一下2的倍数,3的倍数,6的倍数就好了
代码
#include<bits/stdc++.h>
using namespace std;
int n,m;
bool check(int k)
{
int num1 = k/2;
int num2 = k/3;
int num3 = k/6;
if(n>num1)return false;
if(m>num2)return false;
int d = min(num1-n,num3);
if(d+(num2-num3)<m)return false;
return true;
}
int main()
{
scanf("%d%d",&n,&m);
int l = 0,r = 1e7;
int ans = 0;
while(l<=r)
{
int mid = (l+r)/2;
if(check(mid))r=mid-1,ans=mid;
else l=mid+1;
}
cout<<ans<<endl;
}
8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分的更多相关文章
- 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)
题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...
- 8VC Venture Cup 2016 - Elimination Round
在家补补题 模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...
- 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力
D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...
- codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre
C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...
- 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题
F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...
- 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树
G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...
- 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp
F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...
- 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分
E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...
- 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞
B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...
随机推荐
- document.onclick在ios上不触发的解决方法与touchstart点击穿透处理
document.onclick = function (e) { var e = e ? e : window.event; var tar = e.srcElement || e.target; ...
- defconfig file 的 位置
Platform MSM8917 MSM8937 defconfig file position Android/kernel/msm-3.18/arch/arm/configs/
- 【设计模式】迭代器模式(Iterator )
摘要: 1.本文将详细介绍迭代器模式的原理和实际代码中特别是Android系统代码中的应用. 纲要: 1. 引入迭代器模式 2. 迭代器的概念及优缺点介绍 3. 迭代器在Android源码中的应用 1 ...
- 安全测试===sqlmap(零)转载
本文转自:https://blog.werner.wiki/sqlmap-study-notes-0/ 感谢作者的整理,如有侵权,立删 零.前言 这篇文章是我学习Sqlmap的用法时做的笔记,记录了S ...
- NEERC 2016-2017 Probelm G. Game on Graph
title: NEERC 2016-2017 Probelm G. Game on Graph data: 2018-3-3 22:25:40 tags: 博弈论 with draw 拓扑排序 cat ...
- finally
finally 我们都知道无论try语句中是否抛出异常,finally中的语句一定会被执行.我们来看下面的例子: try: f = open("/tmp/output", &qu ...
- HDU-5281
Senior's Gun Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- SQL 分页通用存储过程
USE [DB] GO /****** Object: StoredProcedure [dbo].[SP_AspNetPager] Script Date: 10/23/2015 16:37:33 ...
- Crontab 在linux中的非常有用的Schedule Jobs
crontab 是linux系统集成的定时任务命令,它对于系统运行(数据的备份,调度系统资源或命令,程序的定时触发等非常有用).crontab有些类似于Windows系统的Service的任务计划程序 ...
- PHP超全局变量数组
以下8个变量都是数组变量,又称为“预定义变量” 1.$_GET : 把数据通过地址栏传递到服务器,这是方式必须是$_GET方式传递: 2.$_POST : 通过表单发送的数据必须是POST方式: 3. ...