1 条题解
-
0
题意:
一列人,编号2,3,4,5。。。先选2,然后在没选的里每2个赶走一个,即赶走4,6,8.。。。在从剩下的里选第一个比如i,然后没i个赶走一个,如此反复,求第n个选到的人。
分析:
水题,直接模拟。
代码:
#include <iostream> using namespace std; int a[40024]; int prim[3024]; int main() { memset(a,0,sizeof(a)); int i,j,maxx=40000,cnt=0; for(i=2;i<maxx;++i) if(a[i]==0){ prim[++cnt]=i; int t=0; for(j=i+1;j<maxx;++j){ if(a[j]==0){ ++t; if(t==i){ a[j]=1; t=0; } } } } int n; while(scanf("%d",&n)==1&&n) printf("%d\n",prim[n]); return 0; }
- 1
信息
- ID
- 1453
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 3
- 已通过
- 0
- 上传者