POJ 1017 解题报告
2014-11-17 11:43
239 查看
这道题我用类似枚举的方法做的,比较琐碎。感觉很容易出错,很考验写代码严谨性,WA了一次,还好discuss中又同学给出了测试数据,其中一组数让我找出了bug所在(min写成了max)。
1017 | Accepted | 704K | 63MS | G++ | 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; }
相关文章推荐
- POJ 1017 装箱问题 解题报告
- POJ 1017 装箱问题 解题报告
- POJ 1017解题报告
- POJ1017解题报告
- poj解题报告——1017
- POJ 3159 Candies 解题报告(Dijkstra & SPFA) 及 双向Dijkstra性能测试
- POJ 2446解题报告
- POJ - 2240 Arbitrage解题报告
- POJ-1730 Perfect Pth Powers 解题报告(数论) 最大开方数
- POJ-3122 Pie 解题报告(二分) 平分派饼
- 【解题报告】POJ 1026 Cipher -- 置换群 轮换k次
- 【原】 POJ 1094 Sorting It All Out 拓扑排序 解题报告
- POJ 3468.A Simple Problem with Integers 解题报告
- POJ 1860 解题报告
- 【原】 POJ 1159 Palindrome 回文 动态规划 解题报告
- 【原】 POJ 2388 Who's in the Middle 中位数 解题报告
- POJ 1251 Jungle Roads 解题报告
- 【原】 POJ 3210 Coins 巧妙的简单题 解题报告
- POJ 1062 昂贵的聘礼 解题报告
- POJ(解题报告)