简单的贪心水题
想法很简单,对于5*5的先把1*1的全填进去;
对于4*4的,先填2*2,再填1*1;
对于3*3的,先填2*2,再填1*1。
思路很清晰,但细节总是出错,当填完2*2时可能会剩下用来填1*1的。
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int c1,c2,c3,c4,c5,c6;
int sum;
while(scanf("%d %d %d %d %d %d",&c1,&c2,&c3,&c4,&c5,&c6) == 6 && c1|c2|c3|c4|c5|c6)
{
sum = c6 + c5 + c4;
if(c5 > 0)
c1 = c1 > c5 * 11 ? c1 - c5 * 11 : 0;
if(c4 > 0)
{
int tmp = c2 - c4 * 5;
if(tmp >= 0)
c2 = tmp;
else if(c1 >= 0)
{
c2 = 0;
c1 = c1 > (0 - tmp) * 4 ? c1 - (0 - tmp) * 4 : 0;
}
}
if(c3 > 0)
{
if(c3 % 4 == 0)
{
sum += c3 / 4;
}
else
{
sum += c3 / 4 + 1;
if(c3 % 4 == 1)
{
c2 = c2 > 5 ? c2 - 5 : 0;
if(c2 - 5 >= 0)
c1 = c1 > 7 ? c1 - 7 : 0;
else
{
c1 = c1 > 7 + (5 - c2) * 4 ? c1 - 7 - (5 - c2) * 4 : 0;
}
}
else if(c3 % 4 == 2)
{
c2 = c2 > 3 ? c2 - 3 : 0;
if(c2 - 3 >= 0)
c1 = c1 > 6 ? c1 - 6 : 0;
else
{
c1 = c1 > 6 + (3 - c2) * 4? c1 - 6 - (3 - c2) * 4 : 0;
}
}
else
{
c2 = c2 - 1 ? c2 - 1 : 0;
if(c2 - 1 >= 0)
c1 = c1 > 5 ? c1 - 5 : 0;
else
c1 = c1 > 9 ? c1 - 9 : 0;
}
}
}
if(c2 > 0)
{
if(c2 % 9 == 0)
{
sum += c2 / 9;
}
else
{
sum += c2 / 9 + 1;
int tmp = 36 - c2 % 9 * 4;
c1 = c1 > tmp ? c1 - tmp : 0;
}
}
if(c1 > 0)
{
if(c1 % 36 == 0)
{
sum += c1 / 36;
}
else
sum += c1 / 36 + 1;
}
printf("%d\n",sum);
}
return 0;
}