【CodeForces - 270C】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.

 

题目大意:(练习读题)

已知一个盒子(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的计算几何题处理边的时候就需要这样来着、、)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441175.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

虚拟机安装黑群晖_【群晖系统】HEI群辉DSM 6.2.1 系统安装图文教程 (19年2月)

黑群晖系统其实是指在普通电脑运行Synology DSM系统, 事实上在普通PC电脑上安装黑群晖(Synology DSM)也非常方便, 现在把教程简单写一下。引导系统装哪里&#xff1f;非常关键的问题&#xff0c;DSM采用系统和数据相分离的结构&#xff0c;也就是说引导系统需要独立安装在一个设…

mysql 主从 keepalived_MySQL之双向主从加keepalived高可用

最近在做MySQL数据库的双向主从&#xff0c;了解到keepalived能够自动判断并切换到可用数据库&#xff0c;自己试了一下&#xff0c;整理出文档来。先声明一下环境iptables开启3306端口或者关掉&#xff0c;关闭selinuxMySQL-01&#xff1a;192.168.204.138MySQL-02&#xff1a…

docker启动mysql容器_Docker容器开机自启动

查看所有容器[vagrantlocalhost ~]$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3f142f72d7e8 redis "docker-entr…

【CodeForces - 527C】Glass Carving(线段树或者SBT或者set)

题干&#xff1a; Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm    h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understand…

mysql常驻内存_MySQL的内存和相关问题排查

我们都知道数据库是IO密集型一类应用&#xff0c;为了提高其性能大量使用内存代替文件(交换分区)的IO操作是保证数据库稳定、高效的基本原则。那么数据库是如何使用内存的&#xff0c;我们如何查看数据库内存的占用&#xff0c;如何通过通过数据库内存配置设置提高其性能&#…

java短除法获取二进制_Java十四天零基础入门-Java的数据类型介绍

不闲聊&#xff01;&#xff01;&#xff01;不扯淡&#xff01;&#xff01;&#xff01;小UP只分享Java相关的资源干货本章节目标&#xff1a;理解数据类型的作用。Java中包括哪些数据类型&#xff1f;常见的八种基本数据类型都有哪些&#xff1f;会用八种基本数据类型声明变…

vs怎么把textbox输入的实数放置变量里_方程的计算机处理96(3)_C++vs

计算机语言运用--数值计算9-方程的计算机处理96(3)_Cvs计算机&#xff1a;电子线路组成的计算机器。人与计算机则是通过计算机语言-符号系统说给计算机听而交流。计算机语言有低级语言-机器语言、汇编、高级语言-C/C/C#/VB/PASCAL/LISP/JAVA/PYTHON/……成百上千种之多。作为一…

2008r装mysql_mysql5.7.17在win2008R2的64位系统安装与配置实例

安装MySql操作系统&#xff1a;Windows Server 2008 R2 StandardMySql版本&#xff1a;mysql-5.7.17-winx64第一步&#xff1a;解压mysql-5.7.17-winx64.zip到指定位置第二步&#xff1a;安装文件根目录下添加data文件夹&#xff0c;将my-default.ini重命名为my.ini第三步&…

【HDU - 5187】zhx's contest (快速幂+ 快速乘,模板)

题干&#xff1a; 2018百度之星复赛晋级名单出炉&#xff08;增加20%晋级名额&#xff09;~ zhxs contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3779 Accepted Submission(s): 1226 Problem Desc…

【牛客 - 283E】贪心只能过样例(模拟)

题干&#xff1a; 小西是单身狗&#xff0c;所以她不喜欢看到有CP在秀恩爱&#xff01; 有一天&#xff0c;小西出来闲逛&#xff0c;发现街上的行人都排成了一排&#xff0c;并且可以用这种形式表示&#xff1a; MMFMMFFFMMM 其中M表示男孩子&#xff0c;F表示女装的男孩…

apmserver导入MySQL_mysql数据库导入导出

window下1.导出整个数据库mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -u dbuser -p dbname > dbname.sql2.导出一个表mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名mysqldump -u dbuser -p dbname users> dbname_users.sql3.导出一个数据库结…

【牛客 - 283C】模拟只会猜题意(简单模拟)

题干&#xff1a; 小西突然觉得回文串是一种非常优雅的东西&#xff0c;她突然想要把身边所有的字符串都变成回文&#xff01; 所谓回文串就是一个倒置后仍与自身相等的字符串&#xff0c;如“gxuacmmcauxg”和“gxuacmcauxg”。 小西不喜欢单身狗&#xff0c;所以小西只会…

sql开启mysql远程连接_SQLServer2008设置开启远程连接

SQLServer2008设置开启INTERNET远程连接 SQL Server 2008默认是不允许远程连接的&#xff0c;sa帐户默认禁用的&#xff0c;如果想要在本地用SSMS连接远程服务器上的SQL Server 2008&#xff0c;需要做两个部分的配置&#xff1a; 使用sa账户登录SQL Server Management Studio(…

【牛客 - 283H】图论一顿套模板(思维转化,Dijkstra)

题干&#xff1a; 由于临近广西大学建校90周年校庆&#xff0c;西大开始了喜闻乐见的校园修缮工程&#xff01; 然后问题出现了&#xff0c;西大内部有许许多多的道路&#xff0c;据统计有N栋楼和M条道路&#xff08;单向&#xff09;&#xff0c;每条路都有“不整洁度”W&…

spss相关性分析看结果_spss相关性分析

当我们想要了解变量的相关程度时,就需要用到相关分析,而相关分析也是回归之前很重要的一步,通常用到的方法是pearson方法。 首先解释一下相关系数,相关系数反应的是两个变量之间变化趋势的方向以及程度,其值范围为-1到+1,正值表示正相关,负值表示负相关,绝对值越大表示…

【牛客 - 283F】出装方案(最小费用最大流)

题干&#xff1a; 众所周知&#xff0c;在各种对抗类游戏里装备都是很重要的一环&#xff0c;不同的出装方案会给玩家带来不同的强度。 dalao手里有N件装备&#xff0c;现在dalao要把装备分给N个队友&#xff0c;每个队友只能分一件装备&#xff0c;而每个队友穿上不同的装…

【CodeForces - 289D】Polo the Penguin and Houses (带标号的无根树,Cayley定理,Prufer编码)

题干&#xff1a; Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n). Little penguin Po…

【CodeForces - 289E 】Polo the Penguin and XOR operation (数学,异或,贪心)

题干&#xff1a; Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive. For permutation p  p0, p1, ..., pn, Polo has defined its beauty — number . Expression means applying the operation …

【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题)

题干&#xff1a; Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the …

java生产者消费者代码_Java实现Kafka生产者消费者代码实例

Kafka的结构与RabbitMQ类似&#xff0c;消息生产者向Kafka服务器发送消息&#xff0c;Kafka接收消息后&#xff0c;再投递给消费者。生产者的消费会被发送到Topic中&#xff0c;Topic中保存着各类数据&#xff0c;每一条数据都使用键、值进行保存。每一个Topic中都包含一个或多…