您的位置:首页 > 其它

CODEFORCES 270C Magical Boxes <<小箱子装大箱子>>

2016-07-06 07:25 483 查看
题意:小箱子可以装在大箱子里,给出各种箱子的边长及个数,求把所有箱子装入一个箱子,那么此箱子最小边长是2^i,输出i

样例:

Input
2
0 3
1 5


Output
3


Input
1
0 4


Output
1


Input
2
1 10
2 2


Output
3


#include <iostream>
#include <cstdio>
#define LL long long
#include <cstdlib>
#include <map>
#define MAXN 200005
#include <algorithm>
#include <cmath>
using namespace std;

struct Edge
{
long long ki;
long long ai;
bool operator<(const Edge& ee)
{
return ki > ee.ki;
}
}e[100005];

int main()
{
long n,i;
long long index,ans;
while(cin>> n)
{
index = -1;
for(i=0; i<n; i++)
{
cin>>e[i].ki>>e[i].ai;
if(index < e[i].ki)
index = e[i].ki;
}
sort(e,e+n);
ans = index + 1;
//cout << "ans = " << ans <<endl;
for(int i=0; i<n; i++)
{
index = ans - e[i].ki;
if(index>30)
continue;
index = pow(4.0,index);
while(e[i].ai>index)
{
index*=4;
ans++;
//cout << "index = " << index << endl;
}
}
cout << ans <<endl;
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: