http://acm.tju.edu.cn/toj/showp1022.html - Greedy?
#include <string>
#include <vector>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <memory.h>
using namespace std;
int main(void)
{
int x1,x2,x3,x4,x5,x6,res,klv,x22;
while(scanf("%d%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5,&x6),(x1||x2||x3||x4||x5||x6))
{
res=0;
res+=x6;
if (x5)
{
res+=x5;
klv=11*x5;
x1=min(x1-klv,0);
}
if (x4)
{
res+=x4;
klv=20*x4;
x22=min(klv/4,x2);
x2-=x22;
klv-=x22*4;
x1=min(x1-klv,0);
}
if (x3)
{
res+=x3/4;
if ((x3%4)==1)
{
res++;
klv=27;
x22=min(5,x2);
x2-=x22;
klv-=x22*4;
x1=min(x1-klv,0);
}
if ((x3%4)==2)
{
res++;
klv=18;
x22=min(3,x2);
x2-=x22;
klv-=x22*4;
x1=min(x1-klv,0);
}
if ((x3%4)==3)
{
res++;
klv=9l;
x22=min(1,x2);
x2-=x22;
klv-=x22*4;
x1=min(x1-klv,0);
}
}
if (x2)
{
res+=x2/9;
if (x2%9)
{
res++;
klv=36-(9-x2%9)*4;
x1=min(x1-klv,0);
}
}
if (x1)
{
res+=x1/36;
if (x1%36)
res++;
}
printf("%d\n",res);
}
return 0;
}
http://cybportal.univ.kiev.ua/forum/index.php/board,33.0.html - help, please |