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

来源:互联网 发布:淘宝兼职红包单 编辑:程序博客网 时间:2024/03/29 21:43

题意:小箱子可以装在大箱子里,给出各种箱子的边长及个数,求把所有箱子装入一个箱子,那么此箱子最小边长是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;}


0 0