POJ 1017 解题报告

这道题我用类似枚举的方法做的,比较琐碎。感觉很容易出错,很考验写代码严谨性,WA了一次,还好discuss中又同学给出了测试数据,其中一组数让我找出了bug所在(min写成了max)。

1017Accepted704K63MSG++1629B
/* 
ID: thestor1 
LANG: C++ 
TASK: poj1017 
*/
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <limits>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cassert>

using namespace std;

int main()
{
	std::vector<int> cnt(6, 0);
	while (true)
	{
		bool allzero = true;
		for (int i = 0; i < 6; ++i)
		{
			cin >> cnt[i];
			if (cnt[i])
			{
				allzero = false;
			}
		}

		if (allzero)
		{
			break;
		}

		// 6
		int total = cnt[5];
		
		// 5
		total += cnt[4];
		cnt[0] = max(0, cnt[0] - 11 * cnt[4]);

		// 4
		total += cnt[3];
		cnt[0] = max(0, cnt[0] - max(0, ((5 * cnt[3] - cnt[1]) * 4)));
		cnt[1] = max(0, cnt[1] - 5 * cnt[3]);

		// 3
		total += cnt[2] / 4;
		if (cnt[2] % 4 != 0)
		{
			total++;
			if (cnt[2] % 4 == 3)
			{
				if (cnt[1])
				{
					cnt[1]--;
					cnt[0] = max(0, cnt[0] - 5);
				}
				else
				{
					cnt[0] = max(0, cnt[0] - 9);
				}
			}
			else if (cnt[2] % 4 == 2)
			{
				cnt[0] = max(0, cnt[0] - (18 - 4 * min(cnt[1], 3)));
				cnt[1] = max(0, cnt[1] - 3);
			}
			else
			{
				assert (cnt[2] % 4 == 1);
				cnt[0] = max(0, cnt[0] - (27 - 4 * min(cnt[1], 5)));
				cnt[1] = max(0, cnt[1] - 5);
			}
		}

		// 2
		total += cnt[1] / 9;
		if (cnt[1] % 9 != 0)
		{
			total++;
			cnt[0] = max(0, cnt[0] - (36 - 4 * (cnt[1] % 9)));
		}

		// 1
		total += cnt[0] / 36;
		total += (cnt[0] % 36 != 0);

		cout << total << endl;
	}	
	return 0;  
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值