poj 1012 Joseph

直接打表:

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;
/*class Node
{
public:
      int num;
      Node *next;
};
Node *build( int k )
{
    Node *head = new Node;
    head -> num = 1; head -> next = NULL;
    Node *p = head;
    for( int i = 2 ;i <= 2*k ; i ++ )
    {
        p->next = new Node;        
        p = p -> next;
        p -> num = i ; p -> next = NULL;    
    }
    p->next = head;
    return head;    
}
void Great( )
{
    for( int k = 1; k < 14 ; k ++ )
    {
         int m = k + 1 ;
         while( 1 )
         {
             Node *p = build( k ),*q = p;
             int M = m%( 2*k );
             if( M == 0 )  M = 2*k;
             int t = 1;
             while( t < M )
             {
                   q = p;
                   p = p -> next;
                   
                   t++;                           
             }
             int cnt = 0;
             while( p->num > k )
             {               
               cnt++;
               M = m%( k * 2 - cnt );
               if( M == 0 ) M =  k *2 - cnt ;               
               p = p -> next;
               q->next = p;               
               t = 1;
               while( t < M )
               {
                   q = p;
                   p = p -> next;
                   t++;        
               }
             }
             if( cnt == k ) 
             {
                    num[k] = m;
                    printf( "%d ",m );
                    break;
             }
             m ++;        
         }
    }    
}*/
int main(  )
{
    int num[14]={0,2,7,5,30,169,441,1872,7632,1740,93313,459901,1358657,2504881};   
    int n;
    while( scanf( "%d",&n ), n )
    {
           printf( "%d\n",num[n] );    
    }
    //system( "pause" );
    return 0;
}

 

posted @ 2012-07-21 22:59  wutaoKeen  阅读(121)  评论(0)    收藏  举报