标签:poj
POJ1338 2545 2591 2247都是一个类型的题目,所以放到一起来总结
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 21708 | Accepted: 9708 |
Description
Input
Output
Sample Input
1 2 9 0
Sample Output
1 2 10
找质因子为2、3、5的数,实际这些数就是2、3、5这些数互相乘,从大到小排好序的序列。
发现这种题也有一个固定的套路,也渐渐知道模板题是个什么概念了。
代码:
#include <iostream> using namespace std; int main() { int a[1500]={1},i=1,j2=0,j3=0,j5=0,m,count; while(i<1500) { m=999999999; if(m>2*a[j2])m=2*a[j2]; if(m>3*a[j3])m=3*a[j3]; if(m>5*a[j5])m=5*a[j5]; if(m==2*a[j2])j2++; if(m==3*a[j3])j3++; if(m==5*a[j5])j5++; a[i]=m; i++; } while(cin>>count&&count) { cout<<a[count-1]<<endl; } return 0; }
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6560 | Accepted: 3010 |
Description
Input
Output
Sample Input
7 13 19 100
Sample Output
26590291
代码:
#include <iostream> #pragma warning(disable:4996) using namespace std; #define MAXN 10006 long long a[MAXN]; int main() { a[0] = 1; int i=1,i2,j1=0,j2=0,j3=0,p1,p2,p3; long long m; cin>>p1>>p2>>p3>>i2; while(i<=10005) { m=9223372036854775807; if(m>p1*a[j1]) m=p1*a[j1]; if(m>p2*a[j2]) m=p2*a[j2]; if(m>p3*a[j3]) m=p3*a[j3]; if(m==p1*a[j1])j1++; if(m==p2*a[j2])j2++; if(m==p3*a[j3])j3++; a[i]=m; i++; } cout<<a[i2]<<endl; return 0; }
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9509 | Accepted: 4465 |
Description
Input
Output
Sample Input
100 254
Sample Output
418 1461
#include <iostream> #pragma warning(disable:4996) using namespace std; int a[10000005]; int main() { a[0] = 1; int i=1,j2=0,j3=0; long long m; while(i<=10000000) { m=9223372036854775807; if(m>2*a[j2])m=2*a[j2]+1; if(m>3*a[j3])m=3*a[j3]+1; if(m==2*a[j2]+1)j2++; if(m==3*a[j3]+1)j3++; a[i]=m; i++; } while(scanf("%d",&i)==1) { cout<<a[--i]<<endl; } return 0; }
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9951 | Accepted: 4651 |
Description
Input
Output
Sample Input
1 2 3 4 11 12 13 21 22 23 100 1000 5842 0
Sample Output
The 1st humble number is 1. The 2nd humble number is 2. The 3rd humble number is 3. The 4th humble number is 4. The 11th humble number is 12. The 12th humble number is 14. The 13th humble number is 15. The 21st humble number is 28. The 22nd humble number is 30. The 23rd humble number is 32. The 100th humble number is 450. The 1000th humble number is 385875. The 5842nd humble number is 2000000000.
代码:
#include <iostream> #pragma warning(disable:4996) using namespace std; #define MAXN 10006 long long a[MAXN]; int main() { a[1] = 1; int i=1,i2,j1=1,j2=1,j3=1,j4=1; long long m; while(i<=5842) { m=4000000000; if(m>2*a[j1]) m=2*a[j1]; if(m>3*a[j2]) m=3*a[j2]; if(m>5*a[j3]) m=5*a[j3]; if(m>7*a[j4]) m=7*a[j4]; if(m==2*a[j1])j1++; if(m==3*a[j2])j2++; if(m==5*a[j3])j3++; if(m==7*a[j4])j4++; a[++i]=m; } while(cin>>i2) { if(!i2) break; if((i2%100)>=10&&(i2%100)<=20) { cout<<"The "<<i2<<"th humble number is "<<a[i2]<<"."<<endl; } else if(i2%10==1) { cout<<"The "<<i2<<"st humble number is "<<a[i2]<<"."<<endl; } else if(i2%10==2) { cout<<"The "<<i2<<"nd humble number is "<<a[i2]<<"."<<endl; } else if(i2%10==3) { cout<<"The "<<i2<<"rd humble number is "<<a[i2]<<"."<<endl; } else { cout<<"The "<<i2<<"th humble number is "<<a[i2]<<"."<<endl; } } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ1338 & POJ2545 & POJ2591 & POJ2247
标签:poj
原文地址:http://blog.csdn.net/u010885899/article/details/46906807