DP————1004
2016-05-02 11:09
197 查看
题目:humple number
题意:在(0,5842)范围内求仅有2,3,5,7因子的数列,如1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27。。。为前20个humple number
思路:显然,第一个为1,这个数列按从小到大排列,因子只有2,3,5,7四个数,所以第二个数为2,第三个为3,第 四个为2*2,第五个为5,第六个为3*2,第七个为7,而第八个为2*2*2........ 数列中关于2的与2的倍数有关, 若此次选择的为2的倍数,下一个关于2的数一定是这次选择的倍数乘2。3,5,7一样
感想:在前20个数中查找规律
代码:
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
long long int hum[5866];
hum[1]=1;
int a,b,c,d;
a=b=c=d=1;
int i;
for(i=2;i<5844;i++)
{
hum[i]=min(hum[a]*2,min(hum[b]*3,min(hum[c]*5,hum[d]*7)));
if(hum[i]==hum[a]*2)
a++;
if(hum[i]==hum[b]*3)
b++;
if(hum[i]==hum[c]*5)
c++;
if(hum[i]==hum[d]*7)
d++;
}
int n;
while(~scanf("%d",&n)!=EOF,n)
{
if(n%10==1&&n%100!=11)
scanf("The %dst humble number is %d.\n",n,hum
);
else if(n%10==2&&n%100!=12)
scanf("The %dnd humble number is %d.\n",n,hum
);
else if(n%10==3&&n%100!=13)
scanf("The %drd humble number is %d.\n",n,hum
);
else
scanf("The %dth humble number is %d.\n",n,hum
);
}
return 0;
}
题意:在(0,5842)范围内求仅有2,3,5,7因子的数列,如1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27。。。为前20个humple number
思路:显然,第一个为1,这个数列按从小到大排列,因子只有2,3,5,7四个数,所以第二个数为2,第三个为3,第 四个为2*2,第五个为5,第六个为3*2,第七个为7,而第八个为2*2*2........ 数列中关于2的与2的倍数有关, 若此次选择的为2的倍数,下一个关于2的数一定是这次选择的倍数乘2。3,5,7一样
感想:在前20个数中查找规律
代码:
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
long long int hum[5866];
hum[1]=1;
int a,b,c,d;
a=b=c=d=1;
int i;
for(i=2;i<5844;i++)
{
hum[i]=min(hum[a]*2,min(hum[b]*3,min(hum[c]*5,hum[d]*7)));
if(hum[i]==hum[a]*2)
a++;
if(hum[i]==hum[b]*3)
b++;
if(hum[i]==hum[c]*5)
c++;
if(hum[i]==hum[d]*7)
d++;
}
int n;
while(~scanf("%d",&n)!=EOF,n)
{
if(n%10==1&&n%100!=11)
scanf("The %dst humble number is %d.\n",n,hum
);
else if(n%10==2&&n%100!=12)
scanf("The %dnd humble number is %d.\n",n,hum
);
else if(n%10==3&&n%100!=13)
scanf("The %drd humble number is %d.\n",n,hum
);
else
scanf("The %dth humble number is %d.\n",n,hum
);
}
return 0;
}
相关文章推荐
- java 实际场景下根节点 叶子节点 的不处理方法
- HDU-ACM2041
- 数据处理问题
- Unable to add App ID because the ’10’ app id limit in ‘7’ days has been exceeded
- ones,size和括号()[]{}
- IO
- MIME编码介绍
- 享元模式 (Flyweight)
- 猜数字
- C语言中的printf(),sprintf(),scanf(),sscanf()
- HDU-ACM2040
- [Android] Retrofit 源码分析之 ServiceMethod 对象
- SOAP详解
- 使用zookeeper获取brokers的信息
- C++连接数据库二
- js可选择时分秒的日历时间控件代码下载,多浏览器IE8,9,10、谷歌chrome,火狐firefox等都是兼容的
- 23种设计模式(3):工厂方法模式
- Centos 6.5 安装Asterisk
- HDU-ACM2039
- 适配器模式(Adapter)