poj 2247 Humble Numbers
2012-06-06 09:03
381 查看
//这题与1338的题型是一样的,其做法一样,但是这里的输出需要注意:凡是后两位是11或者是12又或者是13结尾的数字的格式的输出! #include <iostream> #include <algorithm> using namespace std; long humble[6000]; int main() { int i, n2, n3, n5, n7; humble[1] = 1; n2 = 1; n3 = 1; n5 = 1; n7 = 1; for (i = 2; i <= 5900; i++) { humble[i] = min(min(humble[n2]*2, humble[n3]*3), min(humble[n5]*5, humble[n7]*7)); if (humble[i] == humble[n2]*2) n2++; if (humble[i] == humble[n3]*3) n3++; if (humble[i] == humble[n5]*5) n5++; if (humble[i] == humble[n7]*7) n7++; } int num; while (cin >> num && num) { int tmp1, tmp2; tmp1 = num % 10; tmp2 = num % 100; if (tmp1 == 1) { if (tmp2 == 11) cout << "The " << num << "th humble number is " << humble[num] << "." << endl; else cout << "The " << num << "st humble number is " << humble[num] << "." << endl; } else if (tmp1 == 2) { if (tmp2 == 12) cout << "The " << num << "th humble number is " << humble[num] << "." << endl; else cout << "The " << num << "nd humble number is " << humble[num] << "." << endl; } else if (tmp1 == 3) { if (tmp2 == 13) cout << "The " << num << "th humble number is " << humble[num] << "." << endl; else cout << "The " << num << "rd humble number is " << humble[num] << "." << endl; } else cout << "The " << num << "th humble number is " << humble[num] << "." << endl; } system("pause"); }
相关文章推荐
- poj 1338 ugly numbers和poj 2247Humble Numbers 解题报告(附详细分析)
- poj 2247 Humble Numbers
- POJ 2247 && HDU 1058 Humble Numbers(数论)
- poj 2247 Humble Numbers
- poj 2247 Humble Numbers
- poj 2247 Humble Numbers
- POJ 2247 Humble Numbers
- POJ 2247 Humble Numbers
- UVa 443 / POJ 2247 Humble Numbers (4因子-丑数&STL灵活运用)
- PKU 2247 Humble Numbers
- 一类计算问题小结poj&hoj Set Definition ,Humble Numbers ,Ugly Numbers 因子构造法
- POJ 2247 Humble Numbers
- POJ 2247 Humble Numble(我的水题之路——丑数2,3,5,7)
- hdu 1058 Humble Numbers || poj 1338(dp)
- POJ 1995 Raising Modulo Numbers (数论-整数快速幂)
- poj 2739 Sum of Consecutive Prime Numbers (最大连续素数和)
- POJ1995 Raising Modulo Numbers
- Humble Numbers
- POJ 1016 Numbers That Count(string+map)
- POJ 3292 Semi-prime H-numbers(数)