您的位置:首页 > 其它

POJ 1017 解题报告

2014-11-17 11:43 162 查看
这道题我用类似枚举的方法做的,比较琐碎。感觉很容易出错,很考验写代码严谨性,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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: