| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为是么是time limit#include<stdio.h>
int main()
{
int i,m,k,cur,rest;
//k个人
while(scanf("%d",&k)!=0)
{
i=k; // 所求值从k开始一次试探
m=0; // 记录最终答案
if (k == 0) break;
while (1)
{
++i;
rest=2*k; // 所有人数
cur=0; //当前0号为0
while (1)
{
//找到下一个0号的人,如果从0号数,第i个人落在k前面,则杀死好人,不符合要求,break
cur=(cur+i-1)%rest; // find next from ZERO!
//此处cur记录其实为即将被杀死的人的编号,初始i==k,cur == k-1;(第一次杀死的人的编号)
if (cur >= k)
rest--;
else break;
}
//如果剩余人数为k,则坏人均被杀死,返回i即为所取值
if (rest == k)
{
m=i;
break;
}
}
printf("%d\n",m);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator