HDU 4112 Break the Chocolate(模拟)

来源:互联网 发布:数据融合算法 编辑:程序博客网 时间:2024/06/01 13:40

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4112

这个题目半想半猜

首先用手的话比较简单,直接分,先分那面都枚举一下

用刀的话就是一面一面的切

每面长取2的对数,如果是整数,那么就是本身,小数就向上取整

三面这样计算相加,也就是在刀切的时候是对数切割次数,如果有零头就要多切一次

#include <iostream>#include <string.h>#include <stdio.h>#include <algorithm>#include <cmath>using namespace std;#define LL __int64#define MIN(a,b) (a<b?a:b)LL n,m,k;int main(){    //cout<<"k:"<<log2(8)<<endl;    int i,j,Case=0,t;    LL hand,klife,now;    double temp;    scanf("%d",&t);    while(t--){        scanf("%I64d%I64d%I64d",&n,&m,&k);        if(m==1 && n==1 && k==1){            printf("Case #%d: %d %d\n",++Case,0,0);            continue;        }        hand=klife=0;        now=(m-1)+m*(n-1+n*(k-1));        hand=now;        now=(m-1)+m*(k-1+k*(n-1));        hand=MIN(now,hand);        now=(n-1)+n*(m-1+m*(k-1));        hand=MIN(now,hand);        now=(n-1)+n*(k-1+k*(m-1));        hand=MIN(now,hand);;        now=(k-1)+k*(n-1+n*(m-1));        hand=MIN(now,hand);        now=(k-1)+k*(m-1+m*(n-1));        klife=0;        //klife+=n-1+m-1+k-1;        temp=log2(m*1.0);        if(temp-(LL)temp==0)        klife+=(LL)(temp);        else        klife+=(LL)(temp)+1;        temp=log2(n*1.0);        if(temp-(LL)temp==0)        klife+=(LL)(temp);        else        klife+=(LL)(temp)+1;        temp=log2(k*1.0);        if(temp-(LL)temp==0)        klife+=(LL)(temp);        else        klife+=(LL)(temp)+1;        printf("Case #%d: %I64d %I64d\n",++Case,hand,klife);    }    return 0;}


原创粉丝点击