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

题意:小箱子可以装在大箱子里,给出各种箱子的边长及个数,求把所有箱子装入一个箱子,那么此箱子最小边长是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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值