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

约瑟夫

时间:2016-12-15 09:30:39      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:for   step   i++   stdio.h   stdin   ret   break   else   while   

#include<stdio.h>
int k;
int M;
int step[100];
int yue(int m)
{
 int a=0;
 int wo=0;
 for(int i=0;;i++)
 {
  if(wo==k)
   return 1;
  if(step[i%(2*k)]==0)
   continue;
  else
  {
   a++;
   if(a==m)
   {
    if(step[i%(2*k)]<=k)
     return 0;
    else
    {
     step[i%(2*k)]=0;
     wo++;
     a=0;
    }
   }
  }
 }
}
int main()
{
 //freopen("in.txt","r",stdin);
 while(scanf("%d",&k)&&k!=0)
 {
  for(int i=k+1;;i++)
  {
   for(int j=0;j<2*k;j++)
   step[j]=j+1;
   if(yue(i))
   {
    printf("%d\n",i);
    break;
   }
  }
 }
 return 0;
}

约瑟夫

标签:for   step   i++   stdio.h   stdin   ret   break   else   while   

原文地址:http://www.cnblogs.com/452035305qq/p/6181847.html

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