To Be NUMBER ONE
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 395 Accepted Submission(s): 196
Special Judge
Problem Description
One is an interesting integer. This is also an interesting problem. You are assigned with a simple task.
Find N (3 <= N <= 18) different positive integers Ai (1 <= i <= N), and
Find N (3 <= N <= 18) different positive integers Ai (1 <= i <= N), and
Any possible answer will be accepted.
Input
No input file.
Output
Your program’s output should contain 16 lines:
The first line contain 3 integers which are the answer for N = 3, separated by a single blank.
The following 15 lines are the answer for N = 4 to 18, as the same format.
The sample output is the first two lines of a possible output.
The first line contain 3 integers which are the answer for N = 3, separated by a single blank.
The following 15 lines are the answer for N = 4 to 18, as the same format.
The sample output is the first two lines of a possible output.
Sample Output
2 3 6 2 4 6 12
Author
iSea@WHU
Source
Recommend
lcy
算法思想 :
对分母进行分解:
n可以分解成 1/n = 1/(n+1) + 1/(n+1)*n
例如 从2 3 6 开始
不能有相同的 所以只能从 2分解成 3 6 前面已经含有了,然后只能从3开始改
下一项变成 2 4 6 12
下一项不能分解 2因为会多出来6 所以应当选择 2 5 6 12 20
post code:
#include<stdio.h> #include<iostream> #include<algorithm> using namespace std; int a[21][21]; int b[21]; int main() { a[3][1]=2; a[3][2]=3; a[3][3]=6; int i,j,k,len,temp,flag=0; for( i=3; i<=17; i++ ) { len=i; for( j=1; j<=len; j++) { b[j] = a[i][j]; } for( j=1; j<=len; j++) { flag=0; if(b[j]+1!=b[j+1]){ temp=b[j]*(b[j]+1); for(k=1;k<=len;k++) { if(temp==b[k]){flag=1;break;} } if(flag==1)continue; b[j]=b[j]+1; b[len+1]=temp; break; } } sort(b+1,b+len+1+1); for( j=1; j<=len+1; j++) { a[i+1][j]=b[j]; } } for( i=3; i<=18; i++ ) { for( j=1; j<=i; j++ ) { printf("%d",a[i][j]); if(j!=i)printf(" "); } printf("\n"); } }