2010年9月18日 星期六

ACM 311 - Packets

#include <stdio.h>

int residual[6], packets[6];

int main()
{
while (1)
{
int i, isZero = 1, total = 0;
for (i = 0; i < 6; i ++)
{
scanf("%d", &packets[i]);
residual[i] = 0;
if (packets[i] != 0)
isZero = 0;
}
if (isZero) break;
total += packets[5]; /* 6*6一人一個盒子 */
total += packets[4]; /* 5*5一人一個盒子,剩餘 11 個 1*1 空間 */
residual[0] += packets[4] * 11;
total += packets[3]; /* 4*4一人一個盒子,剩餘 5 個 2*2 空間 */
residual[1] += packets[3] * 5;

total += packets[2] / 4; /* 3*3 之處理方式 */
packets[2] %= 4, residual[2] = packets[2];
if (residual[2] == 1)
residual[2] = 0, residual[0] += 7, residual[1] += 5, total ++;
else if (residual[2] == 2)
residual[2] = 0, residual[0] += 6, residual[1] += 3, total ++;
else if (residual[2] == 3)
residual[2] = 0, residual[0] += 5, residual[1] += 1, total ++;

if (residual[1] >= packets[1]) /* 2*2 之處理方式 */
residual[1] -= packets[1], packets[1] = 0;
else
packets[1] -= residual[1], residual[1] = 0;
total += packets[1] / 9;
packets[1] %= 9;
if (packets[1] > 0)
residual[0] += 36 - packets[1] * 4, packets[1] = 0, total ++;
else residual[0] += residual[1] * 4, residual[1] = 0;

if (residual[0] >= packets[0]) /* 1*1 之處理方式 */
residual[0] -= packets[0], packets[0] = 0;
else
packets[0] -= residual[0], residual[0] = 0;
total += packets[0] / 36;
packets[0] %= 36;
if (packets[0] > 0)
total ++;
printf("%d\n", total);
}
return 0;
}

回目錄
回首頁

沒有留言 :

張貼留言

Related Posts Plugin for WordPress, Blogger...