Codeforces 270c Magical Boxes

来源:互联网 发布:首席数据官 能力描述 编辑:程序博客网 时间:2024/03/29 21:49

http://codeforces.com/contest/270/problem/C


每个箱子边长为2的幂,4个小箱子可以放入一个大箱子,给出每种箱子的边长和个数,求将它们全部装下的箱子的最小边长。


一步步推,现将手头上小箱子装入大箱子。


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, 

哪怕只有1个,大箱子也要比它大。

用pow要快的多。。。


#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstdlib>using namespace std;#define N 100005struct po{    int k,a;}b[N];bool cmp(const struct po &x,const struct po &y){    return x.k<y.k;}int main(){    int n;    scanf("%d",&n);    for (int i=1;i<=n;i++) scanf("%d%d",&b[i].k,&b[i].a);    sort(b+1,b+n+1,cmp);    int num=b[1].a;    for (int i=2;i<=n;i++)    {        num=ceil( (double)num/pow(4.0,b[i].k-b[i-1].k) );        if (num<b[i].a) num=b[i].a;    }    double n1=num;    int ans;    if (num==1) ans=b[n].k+1;    else ans=b[n].k+ceil(log(n1)/log(4.0));    printf("%d\n",ans);    return 0;}


原创粉丝点击