You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
# define maxn 25 //n(n<20)个人站成一圈,说好的开大一点, 为啥一下就到25了?
//官员A数k个就停下来
int k ;
//官员B数m个就停下来
int m ;
//n(n<20)个人站成一圈, 逆时针编号为1~ n
int n ;
//标识为0表示离开了~
int a [ maxn ] ;
//从p这个位置开始,( 1表示是逆时针走, -1表示顺时针走) , 走t步
int go ( int p , int d , int t ) {
while ( t - - ) {
do { p = ( p + d + n - 1 ) % n + 1 ; } while ( a [ p ] = = 0 ) ; //走到下一个非0数字
}
return p ;
}
int main ( ) {
//多次输入
while ( scanf ( " %d%d%d " , & n , & k , & m ) = = 3 & & n ) {
//初始化,放过第一个0, 不用
for ( int i = 1 ; i < = n ; i + + ) a [ i ] = i ;
int left = n ; //还剩下的人数
//p1,p2相当于指针, 对准一前一后, 准备开始~
int p1 = n , p2 = 1 ;
//如果还有人剩下
while ( left ) {
//正向走K个
p1 = go ( p1 , 1 , k ) ;
//逆向走M个
p2 = go ( p2 , - 1 , m ) ;
printf ( " %3d " , p1 ) ; //printf("%3d",c)表示域宽为3, 即输出3位
//最少有一个人出局了
left - - ;
//如果一前一后都指向了不是同一个人
if ( p2 ! = p1 ) {
printf ( " %3d " , p2 ) ;
left - - ;
}
//标识这两个人都是出局了~
a [ p1 ] = a [ p2 ] = 0 ;
//如果还有剩余的人员,输出逗号
if ( left ) printf ( " , " ) ;
}
printf ( " \n " ) ;
}
return 0 ;
}