POJ 2247 解题报告
2015-04-16 07:45
253 查看
这道题和1338非常类似。这里用的是http://poj.org/showmessage?message_id=113667里的方法。 注意后缀:11, 113等用的是th,而不是st。12, 212等同理。
thestoryofsnow | 2247 | Accepted | 156K | 32MS | C++ | 1249B |
/* ID: thestor1 LANG: C++ TASK: poj2247 */ #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; const int MAXN = 5842; int main() { int primes[4] = {2, 3, 5, 7}; int nums[MAXN]; nums[0] = 1; int ptr[4] = {0, 0, 0, 0}; for (int i = 1; i < MAXN; ++i) { int num = nums[ptr[0]] * primes[0]; for (int j = 1; j < 4; ++j) { num = min(num, nums[ptr[j]] * primes[j]); } nums[i] = num; for (int j = 0; j < 4; ++j) { if (nums[ptr[j]] * primes[j] == num) { ptr[j]++; } } } // for (int i = 0; i < 20; ++i) // { // printf("%d\t", nums[i]); // } // printf("\n"); int n; char suffix[3][3] = {"st", "nd", "rd"}; while (scanf("%d", &n) && n != 0) { printf("The %d", n); int d = n % 10; if (d == 0 || d > 3 || (10 <= (n % 100) && (n % 100) <= 19)) { printf("th"); } else { printf("%s", suffix[d - 1]); } printf(" humble number is %d.\n", nums[n - 1]); } return 0; }
相关文章推荐
- poj 1338 ugly numbers和poj 2247Humble Numbers 解题报告(附详细分析)
- POJ 1922 解题报告
- POJ 3280 解题报告
- poj 1118 Lining Up 解题报告
- POJ1009 Edge Detection 解题报告
- POJ 1195 解题报告
- POJ 2159 解题报告
- POJ 2159 解题报告
- POJ_2676 数独解题报告
- poj1245解题报告
- POJ 1008 Maya Calendar [解题报告] Java
- POJ 1007(无序度 排序) 解题报告
- POJ 2255 Tree Recovery解题报告
- poj 2342 Anniversary party 树形DP 解题报告
- POJ 1006Biorhythms解题报告——生理周期——【PKU ACM】
- POJ 1654 Area计算几何(解题报告)
- POJ 1496 Word Index组合数学(解题报告)
- POJ_3273Monthly Expense解题报告。
- poj 2406 Power Strings(字符问题)(解题报告)
- POJ 2195 解题报告