Assistance Required hdu 1216 读懂题意很重要 =_=\\
2018-04-04 11:12
274 查看
题意:给你一堆人,标号从2开始依次递增,标号为2的人不用干 活,然后每次往后数2个数,被点到人去干活,一直数到结尾,然后又重头开始,选到第一个不用干活的人的标号为i,然后每次往后数i个数,被点到人去干活,一直数到结尾,就这样循环下去,问第n个不用干活的人的标号是多少?
#include <stdio.h> #include <string.h> #define N 40000 int vis[40005]; int luck[10005]; void get_luck() { int i,j; int k=1; for(i=2;i<=N;i++) { if(!vis[i])//i未被标记过 { luck[k++]=i;//i为幸运数 int cnt=0; for(j=i+1;j<=N;j++) //从i+1开始到N,从未被标记过的数中,每隔i-1个数,标记一下 , { //被标记的数不是幸运数 if(!vis[j]) { cnt++; if(cnt==i) { cnt=0; vis[j]=1; } } } } } } int main() { get_luck(); int n; while(scanf("%d",&n) && n) { printf("%d\n",luck ); } return 0; }
Assistance Required
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2904 Accepted Submission(s): 1558
Problem Description
After the 1997/1998 Southwestern European Regional Contest (which was held in Ulm) a large contest party took place. The organization team invented a special mode of choosing those participants that were to assist with washing the dirty dishes. The contestants would line up in a queue, one behind the other. Each contestant got a number starting with 2 for the first one, 3 for the second one, 4 for the third one, and so on, consecutively.The first contestant in the queue was asked for his number (which was 2). He was freed from the washing up and could party on, but every second contestant behind him had to go to the kitchen (those with numbers 4, 6, 8, etc). Then the next contestant in the remaining queue had to tell his number. He answered 3 and was freed from assisting, but every third contestant behind him was to help (those with numbers 9, 15, 21, etc). The next in the remaining queue had number 5 and was free, but every fifth contestant behind him was selected (those with numbers 19, 35, 49, etc). The next had number 7 and was free, but every seventh behind him had to assist, and so on.
Let us call the number of a contestant who does not need to assist with washing up a lucky number. Continuing the selection scheme, the lucky numbers are the ordered sequence 2, 3, 5, 7, 11, 13, 17, etc. Find out the lucky numbers to be prepared for the next contest party.
Input
The input contains several test cases. Each test case consists of an integer n. You may assume that 1 <= n <= 3000. A zero follows the input for the last test case.Output
For each test case specified by n output on a single line the n-th lucky number.Sample Input
12
10
20
0
Sample Output
23
29
83
相关文章推荐
- hdu 1216 Assistance Required
- HDU1216--Assistance Required HDU(92)
- hdu--2523--读懂题意....
- 杭电ACM1216——Assistance Required~~筛选法的应用
- hdu 4956 Poor Hanamichi(BC.R#5) 读懂了题意就是水题/坑- -比赛中居然没有过
- HDU 1546 Idiomatic Phrases Game(最短路,Dijsktra,理解题意很重要)
- UVA11624 Fire! 两次BFS 读懂题意很重要
- [Swust OJ 188]--异面空间(读懂题意很重要)
- HDU 4930 Fighting the Landlords (超级暴力+读懂题意)
- HDU 1200 扭曲的题意
- HDU 4740 模拟题意
- hdu 1025 Constructing Roads In JGShining's Kingdom(LIS)题意较难转换成LIS
- hdu 4396 More lumber is required
- hdu - 4396 More lumber is required(二维最短路)
- HDU 5310 题意 c语言代码
- HDU 1216 Assistance Required
- HDU 4760 字典树(题意比较难理解)
- hdu 1690 题意 Bus System floyd
- HDU1033 Edge(读懂题目是关键呀,两种方式实现!)
- HDU 1252 Hike on a Graph 题目读懂就能做