zoukankan      html  css  js  c++  java
  • To Be NUMBER ONE

    Problem Description
    One is an interesting integer. This is also an interesting problem. You are assigned with a simple task.<br>Find N (3 &lt;= N &lt;= 18) different positive integers Ai (1 &lt;= i &lt;= N), and<br><center><img src=http://acm.hdu.edu.cn/data/images/C344-1008-1.png></center><br><br>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
    题目要注意,分解出来的数要小于个数加1的平方;
    算法思想 :

    对分母进行分解:

    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

    #include <iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main()
    {int a[400],i,j,flag;
    memset(a,0,sizeof(a));
    a[2]=1;
    a[3]=1;
    a[6]=1;
    printf("2 3 6 ");
    i=4;


    while(i<=18)
    {i++;
    for(j=2;j<i*i;j++)
    {
    if(a[j]&&!a[j+1]&&!a[(j+1)*j])
    {
    a[j]=0;
    a[j+1]=1;
    a[(j+1)*j]=1;
    break;
    }
    }
    flag=1;
    for(j=2;j<(i+1)*(i+1);j++)
    {
    if(a[j])
    {


    if(flag)
    {
    printf("%d",j);
    flag=0;
    }
    else
    printf(" %d",j);
    }
    }
    printf(" ");

    }


    return 0;
    }

  • 相关阅读:
    HDU4366 Successor 线段树+预处理
    POJ2823 Sliding Window 单调队列
    HDU寻找最大值 递推求连续区间
    UVA846 Steps 二分查找
    HDU3415 Max Sum of MaxKsubsequence 单调队列
    HDU时间挑战 树状数组
    UVA10168 Summation of Four Primes 哥德巴赫猜想
    UESTC我要长高 DP优化
    HDUChess 递推
    HDU4362 Dragon Ball DP+优化
  • 原文地址:https://www.cnblogs.com/1314wamm/p/4993109.html
Copyright © 2011-2022 走看看