辽宁省赛——杨鲁斯卡尔专场 -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",n);
break;
}
n=n-n/jian[i];
}
//printf("%d\n",len);
}
system("pause");
return 0;
}

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

时间: 2024-08-14 22:58:54

辽宁省赛——杨鲁斯卡尔专场 -F的相关文章

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

题意: 就是一个人走到一个城市就会记录与该城市相连的城市有多少,最后判断这些城市是否全部相连: 样例输入8 7 7 4 3 3 3 2 1 10 5 4 3 3 2 2 2 1 1 1 样例输出NO YES 解题思路:其实就是判断无向连通图,sum<=(t)*(t-1)/2公式,sum是边长的和,t是顶点个数.不过需要注意的有几点.1.是当输入有0的时候直接就是no因为肯定不可能全部连通.2.是当输入等于2的时候可能这个公式判断不了需要自己做处理.忘了写了打表的代码起就是用数组写的模拟过程,模拟

ACdream原创群赛(13)のwuyiqi退役专场 F The Arrow

F 首先是要理解概率求期望这种题目是用递归来解的! 大概规律就是: 完成事件A的期望是Ea,一次完成的概率是pa,那么 Ea = pa * Ea + (1 + Ea) * (1 - pa) 如果有好多种可能,比方说完成一个事件A的同时,也有诸如事件B的概率期望pb,Eb,事件C的概率期望pc,Ec等等等等,那么就分别写出来: Ea = pa * Ea + (1 + Ea) * (~pa) + pb * (1 + Eb) + pc * (1 + Ec) + ... 其中~pa是除了这些已知的事件发

2014辽宁省赛 Traveling

问题 K: Traveling 时间限制: 1 Sec  内存限制: 128 MB 提交: 13  解决: 4 [提交][状态][论坛] 题目描述 SH likes traveling around the world. When he arrives at a city, he will ask the staff about the number of cities that connected with this city directly. After traveling around 

[ACM]辽宁省赛2010 (HZNU 1081-1089)

虽然退役了,但偶尔水几题醒醒脑还是不错的=_= 1085 Intermediary 暂时还没做 1081: Dinner 时间限制: 1 Sec  内存限制: 32 MB提交: 5  解决: 3[提交][状态][讨论版] [Edit] [TestData] 题目描述 Little A is one member of ACM team. He had just won the gold in World Final. To celebrate, he decided to invite all

2010辽宁省赛 NBUT 1222 English Game【字典树+DP】

[1222] English Game 时间限制: 1000 ms 内存限制: 131072 K 链接:Click Here! 问题描述 This English game is a simple English words connection game. The rules are as follows: there are N English words in a dictionary, and every word has its own weight v. There is a wei

ACdream原创群赛(13)のwuyiqi退役专场 H Salmon And Cat

H 首先是要姿势正确! 注意完美数的生成机: 2+2a+2b+ab ab都是完美数 假设生成完美数c c = 2 + 2a + 2b + ab c + 2 = ab+2a+2b+4 c + 2 = (a + 2)(b + 2) 然后一开始只有两个完美数1和3. 所以所有的完美数只有质因数分解之后都是类似于 N = (3 ^ x) * (5 ^ y) 但是5不是完美数. 然后就没事了... /**** *COPYRIGHT NOTICE *Copyright (c) 2014 *All right

最小生成树(卡鲁斯卡尔)

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2896 最小生成树:n个顶点n-1条边 本题因为有50000个点,所以只能用Kuscal #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> using n

七夕专场-F题

LH很聪明.每次这种题目,他想想就有结果了,我得琢磨一阵才恍然大悟.诶,智商不在一个等级啊.其实是用做差,一直用新读入的减去前面2个数之差.sum为0就满足. #include<iostream> using namespace std; int g[10010]; int main() { int t,m; cin >> t; while(t--) { cin >> m; int sum = 0; for(int i = 0;i <m;i++) { cin &g

“玲珑杯”线上赛 Round #17 河南专场

闲来无事呆在寝室打打题,没有想到还有中奖这种操作,超开心的 玲珑杯"线上赛 Round #17 河南专场 Start Time:2017-06-24 12:00:00 End Time:2017-06-24 14:30:00 Refresh Time:2017-06-24 14:48:00 Private A -- Sin your life Time Limit:1s Memory Limit:128MByte Submissions:529Solved:76 DESCRIPTION 给一个正