HDU 3816 To Be NUMBER ONE

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


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.
 

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");
     }
    
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值