Follows 130.c (Total 74 lines):

/* @JUDGE_ID:4461XX 130 C */
/* A */
#include <stdio.h>
struct man{
	int from ;
	int killed ;
	int next ;
}man[150] ;
int before , after ;
void make_cir( int n )
{
	int i ;
	for( i=0 ; i<n ; i++ ){
		man[i].from = (i-1+n)%n ;
		man[i].next = (i+1)%n ;
		man[i].killed = 0 ;
	}
}
void kill( int j )
{
	man[j].killed = 1 ;
	man[man[j].from].next = man[j].next ;
	man[man[j].next].from = man[j].from ;
	before = man[j].from ;
	after = man[j].next ;
}
void bury( int f )
{
	if( f == before || f == after ) return ;
	man[man[f].from].next = man[f].next ;
	man[man[f].next].from = man[f].from ;
	man[before].next = man[after].from = f ;
	man[f].next = after ;
	man[f].from = before ;
}
int run( int n , int k , int i )
{
	int j , killed , m , f , g ;
	for( j=i , killed=0 , m=0 ; killed!=n-1 ; j=man[j].next )
		if( !man[j].killed ){
			m++ ;
			if( m==k ){
				if( j==0 ) return 0 ;
				kill( j ) ;
				killed++ ;
				for( f=man[j].next , g=0 ; ; f=man[f].next )
					if( !man[f].killed ){
						g++ ;
						if( g==k ){
							bury( f ) ;
							j = f ;
							break ;
						}
					}
				m = 0 ;
			}
		}
	return 1 ;
}
void main( void )
{
	int n , k , i ;
	while( 1 ) {
		scanf( "%d %d" , &n , &k ) ;
		if( !n && !k ) break ;
		for( i=0 ; i<n ; i++ ){
			make_cir( n ) ;
			if( run( n , k , i ) ){
				printf( "%d\n" , i+1 ) ;
				break ;
			}
		}
	}
}

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