题干:

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.

题目大意:(练习读题)

已知一个盒子(2^k)可以套四个小盒子(不能套和自己一样大的盒子!)

如果一个盒子的边长大于另一个盒子,那么这个盒子就能够容纳那另一个盒子 。

问用多大边长的正方形盒子,能够容纳所有给出的盒子。(也就是,如果全程一个盒子,需要再来一个盒子!读题!)

第一行给出总共盒子数n,下面n行,每行两个整数,分别代表盒子的大小  和  该大小盒子的盒子数量。(其中第一个盒子是用2的幂次给出。)

解题报告:

这题我好像做麻烦了,,本来想直接用数组下标代表2的幂次来着,,数量1e9的话也就是说幂次也就几百而已。。但是发现是幂次是2e9(也就是说这题全程在用幂次,跟具体数字完全无关了),,所以就不能直接用数组了,,考虑用map离散化一波,,不算难写但是还是有坑的,比如不能直接除以4,,因为不一定相邻两个大小的盒子一定是大小相差1的,,仔细理解下就能看出来。(其实看了标解后发现不需要存数据的,,直接on_process一波就ok了)

AC代码1:(直接on出结果的)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
map<ll,ll> mp;
int main()
{int n;ll ans = 0;ll num,tmp,k;cin>>n;for(int i = 1; i<=n; i++) {scanf("%lld%lld",&k,&num);if(num == 1) k++;while(num > 1) {tmp = num%4 == 0 ? num/4 : num/4+1;num = tmp;k++;}ans = max(ans,k);}printf("%lld\n",ans);return 0 ;}
/*
2
0 3
1 5*/

AC代码2:(map处理的)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
map<ll,ll> mp;
int main()
{int n;ll tmp,num;ll ans = 0;cin>>n;for(int i = 1; i<=n; i++) {scanf("%lld",&tmp);scanf("%lld",&num);ans = max(ans,tmp);mp[tmp] += num;}   map<ll,ll> :: iterator it = mp.begin(),end=mp.end(),ii;--end;for(;it != end; ++it) {num = it->se;++it;ii=it;--it;ll pp = pow(4,ii->fi - it->fi);tmp = num%pp == 0 ? num/pp : num/pp + 1;++it;if(it->se < tmp) {it->se += (tmp - it->se); }--it;}num = end->se;if(num == 1) {printf("%lld\n",ans+1);return 0 ;}while(num >= 4) {tmp = num%4 == 0 ? num/4 : num/4 + 1;num=tmp;ans++;}ll out = num == 1 ? ans : ans+1;if(out==0) out=1;printf("%lld\n",out);return 0 ;}

总结:  掌握那种tmp=的那种方式,,经常需要处理一波(记得那次那个记忆化dp的计算几何题处理边的时候就需要这样来着、、)

【CodeForces - 270C】Magical Boxes (思维,进制,有坑)相关推荐

  1. Codeforces 552C Vanya and Scales(进制转换+思维)

    题目链接:http://codeforces.com/problemset/problem/552/C 题目大意: 有101个砝码重量为w^0,w^1,....,w^100和一个重量为m的物体,问能否 ...

  2. 牛客 - Hash(思维+进制转换)

    题目链接:点击查看 题目大意:给出一个长度为 6 的字符串 s ,再给出模数 mod,现在规定哈希值为如下运算: const int LEN = 6; int mod; int Hash(char s ...

  3. CodeForces PYM101158CSU2294 Hidden Anagrams 26进制 前缀和

    题目: http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2294 http://codeforces.com/gym/101158/a ...

  4. Educational codeforces round 83 div2C(类似进制转换,等比数列又一个性质)

    C. Adding Powers 原题目地址 题意: 给你一个目标数组,要你 对一个所有元素从0开始的数组 进行一种操作. 每一步可以对一个元素增加 k^i ( i 为每一步)( i 可以为0) 或者 ...

  5. X 进制转十进制黄金万能算法

    单纯.混合进制通吃,真正的黄金万能的进制转换方法. [学习的细节是欢悦的历程] Python 官网:https://www.python.org/ Free:大咖免费"圣经"教程& ...

  6. Codeforces Round #730 (Div. 2) D2. RPD and Rap Sheet (Hard Version) 交互 + k进制的转换

    传送门 文章目录 题意: 思路: 题意: 定义a⊕kba\oplus_k ba⊕k​b为a,ba,ba,b在kkk进制下的不进位加法.系统会随机生成一个数xxx,你猜这个数,假设当前猜的数为yyy,如 ...

  7. 【EOJ Monthly 2019.02 - D】进制转换(思维,取模,高精度大数)

    题干: 单测试点时限: 2.0 秒 内存限制: 256 MB "他觉得一个人奋斗更轻松自在.跟没有干劲的人在一起厮混,只会徒增压力." QQ 小方决定一个人研究研究进制转换. 很快 ...

  8. 程序员的数学思维修炼(趣味解读)还有哪些进制

    其实,除了我们常用的十进制数和电脑用的二进制数之外,生活中还有很多的计数进 制,并且有很多的进制也在电脑中使用. 1.4.1    神奇的八卦:八进制 八卦最初是上古人们记事的符号,后被用为 卜筮符号 ...

  9. 试题C:乘积尾零 / 试题G:冷门进制 (思维)

    试题C:乘积尾零 给出以下数据(10行每行10个),求出它们的乘积末尾有多少个0? 5650 4542 3554 473 946 4114 3871 9073 90 4329 2758 7949 61 ...

最新文章

  1. C语言精要总结-指针系列(二)
  2. 单例模式到Java内存模型
  3. React之JSX入门
  4. Lucene.Net 2.3.1开发介绍 —— 二、分词(五)
  5. OJ1066: 字符分类统计
  6. 网游UI解决方案的选择(作者 鸣·铭)
  7. 2021江西高考成绩6月23日几点查询,2021年江西高考成绩查询时间:6月23日
  8. 2019.02.12 bzoj3944: Sum(杜教筛)
  9. Python开发环境搭建方法简述
  10. 手机中CAD图纸发送到电脑上后打不开了怎么办?
  11. 【vue源码工程阅读1:下载源码】认识工程并打包
  12. 快速实现APP混合开发(Hybrid App开发)攻略
  13. 用户绑定手机号的思考
  14. 企业估值研究到底从何处着手?
  15. 智能优化算法:海鸥算法原理及Matlab代码
  16. unity中怎么让物体位置复位_(转)Unity3D中移动物体位置的几种方法
  17. 小米实习面试总结(1)
  18. Odoo产品分析 (三) -- 人力资源板块(4) -- 招聘流程(1)
  19. Python全国二级等级考试 资源!
  20. 微信小程序 - 沉浸式抽屉(非组件)

热门文章

  1. SQL Server 清空或删除所有数据库表中的数据
  2. 162. Find Peak Element
  3. [小技巧][JAVA][转换]整型int与字符串String相互转换
  4. [Leedcode][JAVA][第45题][跳跃游戏 II][贪心算法]
  5. unionall mysql_5分钟了解MySQL5.7union all用法的黑科技
  6. 华为swot分析2020_科技口译现场:华为2020全球分析师大会
  7. mysql 创建查询 删除_MYSQL数据库查询删除创建企业基本知识
  8. 华为h22h05服务器做raid_华为V5服务器 RAID控制卡(LSI SAS3008IR)
  9. 服务器交换机项目购买,四川大学网络空间安全研究院服务器、交换机等采购项目...
  10. 服务器网盘系统怎么装,云服务器上怎么安装操作系统