• 辽宁省赛——杨鲁斯卡尔专场 -F


    题意:

    题意就是输入N以EOF结尾,形成1-N的数字序列,然后选取一个幸运数字,每隔幸运数字的长度就将数字从序列中删掉,

    选取幸运数字的规则是最开始是2,之后删掉数字之后每次选取序列中除1和选过的幸运数字外最小的。3<=n<=10000)

    样例输入

    20
    30
    

    样例输出

    6
    8
    

    提示

    eg.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20


    For the first time, delete the last number in every two numbers. The sequence become 1 3 5 7 9 11 13 15 17 19


    For the second time, the minimum number that has never been used is 3. Delete the last number in every 3 numbers. The sequence become 1 3 7 9 13 15 19


    For the third time, the minimum number that has never been used is 7. Delete the last number in every 7 numbers. The sequence becomes 1 3 7 9 13 15.


    Then you cannot delete any numbers. There are 6 numbers left over. So the answer is 6.

    解题思路:

    这题看着是一道模拟题,但是用模拟写一直超时,可能学的还不太好。之后发现了一个规律,幸运数字的选取看似是

    随机的其实不是,是一个固定的序列,n的范围最大是10000所以可以打表,将幸运数字都打表下来,然后可以找到一个

    公式,就是每次需要按照幸运数字减少多少。(注释:用c的输入输出比c++要快好多倍,至少这题一个时间是600多一个

    是40多)

    具体代码:

    #include<iostream>
    #include<stdio.h>
    #include<vector>
    #include<iterator> 
    #include<cstring>
    using namespace std;
    int pp[10005];
    int jian[180]={2,3,7,9,13,15,21,25,31,33,37,43,49,51,63,67,69,73,75,79,87,93,99,105,111,115,127
    ,129,133,135,141,151,159,163,169,171,189,193,195,201,205,211,219,223,231,235,237
    ,241,259,261,267,273,283,285,289,297,303,307,319,321,327,331,339,349,357,361,367
    ,385,391,393,399,409,415,421,427,429,433,451,463,475,477,483,487,489,495,511,517
    ,519,529,535,537,541,553,559,577,579,583,591,601,613,615,619,621,631,639,643,645
    ,651,655,673,679,685,693,699,717,723,727,729,735,739,741,745,769,777,781,787,801
    ,805,819,823,831,841,855,867,873,883,885,895,897,903,925,927,931,933,937,957,961
    ,975,979,981,991,993,997,1009,1011,1021,1023,1029,1039,1041,1053,1057,1087,1093,
    1095,1101,1105,1107,1117,1123,1147,1155,1167,1179,1183,1189,1197,1201,1203,1209};
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            for(int i=0;i<180;i++)
            {
                if(n<jian[i])
                {
                    printf("%d
    ",n);
                    break;
                }
                n=n-n/jian[i];
            } 
            //printf("%d
    ",len);       
        }
        system("pause");
        return 0;   
    }
    View Code
  • 相关阅读:
    java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport
    project configuration is not up-to-date with pom.xml
    消息列队5
    消息列队4
    消息列队3
    聊聊常见的数据库架构设计方案?
    消息队列2
    消息队列1
    搜索引擎5
    搜索引擎4
  • 原文地址:https://www.cnblogs.com/baoluqi/p/3731905.html
Copyright © 2020-2023  润新知