joj 1097 System overload 约瑟芬问题 简单题

joj 1097 System overload 约瑟芬问题 简单题

题意好理解,时间上提高不了,测试数据很少可以交表

点+展开
#include<iostream>
#include
<cstdlib>
using namespace std;

  
int main()
  {
  
//freopen("s.txt","r",stdin);
  
//freopen("key.txt","w",stdout);
  int n,i,length,k,cursor,cycle,left;
  
while(cin>>length,length)
  {
        
bool mark[151];    
        
for(i=2;;i++)
        {    
            cycle
=i;//³¢ÊÔ²½³¤Îªi;
            cursor=0//Ö¸ÏòλÖà
            memset(mark,0,sizeof(mark));
            mark[
0]=true;
            left
=length-1;
            
while(left>0)
           {
            left
--;    
            k
=0;            
            
while(k<cycle)
            {
                cursor
=(cursor+1)%(length);
                
if(mark[cursor]==false)
                    k
++;
            }
            
if(cursor==1)
              
break;
            
else
              mark[cursor]
=true;
            }
           
if(left==0)
           
break
        }
        cout
<<i<<endl;
  }

  
//system("PAUSE");
  return   0;
  }

你可能感兴趣的:(joj 1097 System overload 约瑟芬问题 简单题)