codeforce 270C Magical Boxes
C. Magical Boxes
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2k - 1 into one box of side length 2k, or as in the following figure:
Emuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.
Input
The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct.
Output
Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p.
Examples
input
2
0 3
1 5
output
3
input
1
0 4
output
1
input
2
1 10
2 2
output
3
Note
Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2.
题目大意:
问用多大边长的正方形盒子,才能够能够装下所有给出的盒子
其中,如果一个盒子的边长大于另一个盒子,那么这个盒子就能够容纳那另一个盒子 。
思路:
我们先将盒子按照从小到大排序,那么对于临近的两个大小的盒子,我们考虑将小盒子放在大盒子中, 如果容纳不下,那么就相当于再多开几个大盒子。用这个贪心的思想,最后放完之后,还剩多少盒子,即外层盒子。
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
#define LL long long
#define MAXN 100100
struct node
{
LL x;
LL y;
} a[MAXN*2];
bool cmp(node u,node v)
{
return u.x<v.x;
}
int main()
{
LL n,i,j;
cin>>n;
for(i=1; i<=n; i++)
cin>>a[i].x>>a[i].y;
sort(a+1,a+n+1,cmp);
LL k=a[1].x,l=a[1].y;
for(i=2; i<=n; i++)
{
if(a[i].x==k)
l=l+a[i].y;
else
{
LL b=a[i].x-k;
for(j=1; j<=b; j++)
{
if(l%4==0)
l=l/4;
else
l=(l/4)+1;
if(l==1)
break;
}
k=a[i].x,l=max(l,a[i].y);
}
}
while(1)
{
if(l==1)
break;
if(l%4==0)
l=l/4;
else
l=(l/4)+1;
k++;
}
if(k==a[n].x)
cout<<k+1;
else
cout<<k;
return 0;
}
codeforce 270C Magical Boxes的更多相关文章
- Codeforces Round #165 (Div. 2)
C. Magical Boxes 问题相当于求\[2^p \gt \max{a_i \cdot 2^{k_i}},p \gt k_i\] D. Greenhouse Effect \(dp(i,j)\ ...
- codeforce C. Okabe and Boxes
题目传送门 这道题 每次删除一个点 那么这个点必然在栈里面 那么如果堆顶不是他 我们就需要一次操作使得堆合理 这时我们可以把他删除然后把他下面的点打个标记表示这下面的点以后想怎么排就怎么排以后都不需要 ...
- Magical平台类库代码分享
这些天闲来无事,就整理了一些类库.jQuery插件和自定义控件.今天和大家分享下Magical平台类库代码. 下图为整个解决方案图.MagicalPlatForm里面定义的是众多的Layer层:Mag ...
- Fedora 24 Gnome Boxes 无法ping通网络
安装Fedora 24在试用虚拟机时发现无法ping通外网. 我傻傻地以为是软件问题. 问题描述: 尝试ping程序来测试网络连通性: (我之前也是ping百度,后来在为了少打字百度了一些比较短的域名 ...
- STL : map函数的运用 --- hdu 4941 : Magical Forest
Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- hdu4941 Magical Forest (stl map)
2014多校7最水的题 Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit ...
- Problem B Boxes in a Line
省赛B题....手写链表..其实很简单的.... 比赛时太急了,各种手残....没搞出来....要不然就有金了...注:对相邻的元素需要特判..... Problem B Boxes in a Li ...
- Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s
C. Inna and Candy Boxes Inna loves sweets very much. She has n closed present boxes lines up in a ...
- Open judge C16H:Magical Balls 快速幂+逆元
C16H:Magical Balls 总时间限制: 1000ms 内存限制: 262144kB 描述 Wenwen has a magical ball. When put on an infin ...
随机推荐
- flask开启调试的四种模式
flask开启调试的四种模式 在app.run()中加一个参数, 'debug=True'就可以开启debug模式 from flask import Flask app = Flask(__name ...
- Java第四天,随机数如何生成?ArrayList如何使用?
虽然很多时候我们查阅Java API文档,但是对于一些必要的类,我们还是需要去了解的.因为这样的情况下,我们就可以尽量的去缩短开发的周期.接下来我们认识一下哪些API类是必须熟记的. Random 这 ...
- 9.2ArrayList 集合 案例,学生管理系统
循环的使用 添加学生:while嵌套for,for设置变量,内嵌if更新变量.if语句判断变量值 修改学生:for循环内嵌if,获取循环中的某个值. package day9_ArrayList.AL ...
- Python操作rabbitmq系列(二):多个接收端消费消息
今天,我们要逐步开始讨论rabbitmq稍微高级点的耍法了.了解这一步,对我们设计高并发的系统非常有用.当然,还可以使用kafka.不过还是算了,有几个硬性条件不支持,还是用rabbitmq吧. 循环 ...
- 理解JSON:3分钟课程
理解JSON:3分钟课程 博客分类: Java综合 jsonAjaxJavaScriptXMLLISP 本文是从 Understanding JSON: the 3 minute lesson 这篇文 ...
- java课程设计之--Elasticsearch篇
一.团队课程设计博客链接 https://www.cnblogs.com/Rasang/p/12169899.html 二.个人负责模块或任务说明 2.1Elasticsearch简介 Elastic ...
- Extjs——简单的Grid panel小实例
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- 复习python的多态,类的内部权限调用 整理
#多态的用法 class Dii: passclass Aii(Dii): def run(self): print('一号函数已调用')class Bii(Dii): def run(Dii): p ...
- C - N皇后问题 DFS
在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上. 你的任务是,对于给定的N,求出有多少种合法的放置方法. Inpu ...
- Laravel - 上手实现 - 文件上传、保存到 public 目录下
1.为了访问方便,将上传的文件保存在 public 目录下,需要进行修改配置. 找到 config/filesystems.php 文件然后修改 root.具体如下: 'local' => [ ...