Follows 440.c (Total 46 lines):

/* @JUDGE_ID:4461XX 440 C */
/* A */
#include<stdio.h>
struct queue{
        int killed ;
        int next ;
}QUEUE[150] ;
int n ;
int kill( int i )
{
        int k , time , people , j ;
        for( k=1 , time=1 , people=1 ; people<n-1 ; k=QUEUE[k].next , time++ )
                if( time==i ){
                        if( !QUEUE[k].killed ){
                                if( k == 1 ) return 0 ;
                                else{
                                        QUEUE[k].killed = 1 ;
                                        for( j=0 ; j<n ; j++ )
                                                if( QUEUE[j].next == k ) QUEUE[j].next = QUEUE[k].next ;
                                        people++ ;
                                        time = 0 ;
                                }
                        }
                        else return 0 ;
                }
        return 1 ;
}
void main( void )
{
        int i , j ;
        while( 1 ){
                scanf( "%d" , &n ) ;
                if( !n ) break ;
                for( i=2 ; ; i++ ){
                        for( j=0 ; j<n ; j++ ){
                                QUEUE[j].killed = 0 ;
                                QUEUE[j].next = (j+1)%n ;
                        }
                        QUEUE[0].killed = 1 ;
                        QUEUE[n-1].next = 1 ;
                        if( kill( i ) ) break ;
                }
                printf( "%d\n" , i ) ;
        }
}


Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com