poj 2244 Eeny Meeny Moo

直接打表:

View Code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#include<vector>
#include<string>
#define LL long long
using namespace std;
void Get_num( int num[] )
{
    bool hash[160];   
    for( int i = 3 ; i <= 150 ; i ++ ){
         int m = 1;
         while( 1 ){
            int M = m % i;
            memset( hash , 0 , sizeof( hash ) );
            hash[0] = true;
            int t = 0,sum=0;
            while( t != 1  ){                
                sum ++;    
                M = m % ( i - sum );
                if( M == 0 ) M = i - sum;        
                hash[t] = true;    
                t++;
                t %= i;
                int cnt = 0;
                while( cnt < M ){
                     if( !hash[t] )  cnt++;                            
                     t++;    
                     t %= i;
                } 
                if( t == 0 ) t = i -1;
                else t --;
            }
            if( sum == i -1 ){
               num[i] = m;
               break;
            }
            m ++;
         }    
    }    
}
int main(  )
{
    int num[160];
    num[2] = 1;
    Get_num( num );
    int n;
    while( scanf( "%d",&n ),n )
    {
         printf( "%d\n",num[n] );    
    }
    //system( "pause" );
    return 0;
}

 

posted @ 2012-07-22 09:58  wutaoKeen  阅读(126)  评论(0编辑  收藏  举报