码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-05-19 10:20:26      阅读:303      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   c   tar   

题意:

题意就是输入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多)

 

具体代码:

 

bubuko.com,布布扣
#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",n);
                break;
            }
            n=n-n/jian[i];
        } 
        //printf("%d\n",len);       
    }
    system("pause");
    return 0;   
}
View Code

 

 

 

辽宁省赛——杨鲁斯卡尔专场 -F,布布扣,bubuko.com

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

标签:style   blog   class   code   c   tar   

原文地址:http://www.cnblogs.com/baoluqi/p/3731905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!