标签:dp
题目链接:http://acm.acmcoder.com/showproblem.php?pid=1058
题意:数字只有2,3,5,7素因子的数叫做Humble Number,问你第 n 个Humble Number是什么?
解法:枚举。
代码:
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <fstream>
#include <set>
#include <map>
#include <math.h>
using namespace std;
int n;
int p[6000];
int tmp[5] = { 2, 3, 5, 7 };
set<long long> SET;
void init()
{
p[1] = 1;
int n = 1, m = 1, k = 1, l = 1;
for (int i = 2; i <= 5842; i++)
{
int a = p[n] * 2;
int b = p[m] * 3;
int c = p[k] * 5;
int d = p[l] * 7;
int ans = min(a,min(b,min(c,d)));
if (ans == a) n++;
if (ans == b) m++;
if (ans == c) k++;
if (ans == d) l++;
p[i] = ans;
}
}
int main()
{
init();
while (scanf("%d",&n)!=EOF && n)
{
printf("The %d",n);
if (n % 100 == 13 || n % 100 == 12 || n % 100 == 11)
printf("th");
else if (n % 10 == 1) printf("st");
else if (n % 10 == 2) printf("nd");
else if (n % 10 == 3) printf("rd");
else printf("th");
printf(" humble number is %d.\n",p[n]);
}
return 0;
}
标签:dp
原文地址:http://blog.csdn.net/u014427196/article/details/46379515