acm hnu 134 Joseph's Puzzle

Joseph's Puzzle
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 134, Accepted users: 125
Problem 10045 : No special judgement
Problem description
Persons, whose number order is from 1 to N, hold a password (the straight integer less than 10000) each person and sit around clockwise.
At first we choose a positive integer factor as the count off number M and start to number clockwise from number one .As we number to M the person who numbers M leaves the rank and whose password will be the new number M. And then start to number again from the person who is sit clockwise next to the person who has been out off the rank just before then. Continue like this, until all people are out off the rank completely. Please design a program of leaving order.

Input
There have some groups data. First line of each group data is two integers N, M (0<N, M<100),the second line is N positive integer, separately express every person’s password.The last line contins 0,0 ,which means the end of input data.

Output
To each group of data, according to the order which leaves outputs their serial number. Between the numeral separates with a blank space. Each group of data monopolize line of outputs.

Sample Input
7 20
3 1 7 2 4 8 4
4 3
1 2 3 4
0 0
Sample Output
6 1 4 7 2 3 5
3 2 1 4
Problem Source
HNU 1'st Contest

/* 18:10~   */



#include 
< stdio.h >

#define  MAX 50000

int  move(  int  num[], int  Mr );

main()

{

      
int  num[MAX],n,Mright = 0 ,p = 0 ,total = 0 ,M = 0 ,Mr = 0 ;

      
int  i,j;

      i 
=   0 ;

      
for  (i  =   0  ; i  <  MAX ; i ++ )num[i] =- 2
                

      scanf(
" %d%d " , & n, & M);

      
for  (i  =   0  ; i  <  n ; i ++ )scanf( " %d " , & num[i]); 

      
while ( n != 0   &&  M != 0  ){

             total 
=  n;

             

             p 
=   0 ;

             Mr 
=  M % n;

             
while ( total  >   0  ){

                    p
= move(num,Mr);

            
if (total == 1 ){printf( " %d " ,p + 1 ); break ;}

            
else   printf( " %d  " ,p + 1 );

            M 
=  num[p]; // record M

            num[p]
=- 1 ;

            total
-- ;

            p
++ ;     // delete it

                    M
= M % total;

            
// caculate the amount after this

            i
= p;

            Mright
= 0 ;

            
while (num[i] !=- 2 ){

              
if (num[i] !=- 1 )Mright ++ ;

              i
++ ;

            }

            
if (M == 0 && total == 1 ){Mr = 1 ; continue ;}

            
if (M == 0 )Mr = total - Mright;

            
else   if (M > Mright)Mr = M - Mright;

            
else  Mr = total + M - Mright;

          }
// while total

              
for  (i  =   0  ; i  <  MAX ; i ++ )num[i] =- 2 ;             

              scanf(
" %d%d " , & n, & M);
              
for  (i  =   0  ; i  <  n ; i ++ )scanf( " %d " , & num[i]); 

      }

 
return   0 ;
}



// return current p,M < total

int  move(  int  num[], int  Mr )

{

    
int  c = 0 ,p = 0 ;

    
while ( 1 ){

             
if ( num[p]  !=   - 1  ){ 

                 c
++ ;

                
if (c  ==  Mr) return  p;

                 }

                 p
++ ;

             }



}

### HNU ACM 2024 Competition Information and Team Details HNU ACM团队积极参与各类编程竞赛活动,旨在提升成员算法设计与实现能力。对于即将举行的2024年比赛,参赛者需关注官方渠道发布的最新通知来获取确切的比赛时间表、规则变化以及报名方式等重要信息[^1]。 #### 团队构成 该队伍由来自不同年级的学生组成,他们拥有丰富的解题经验和扎实的理论基础,在历届赛事中取得了优异的成绩。新老队员之间相互学习交流,共同进步成长。此外,学校还邀请了多位经验丰富的指导教师参与培训工作,帮助学生更好地准备比赛。 #### 训练资源 为了提高选手们的实战水平,HNU ACM提供了多种训练途径: - **在线评测平台**:通过解决平台上提供的题目积累经验; - **内部讲座和技术分享会**:定期举办专题研讨会,深入探讨特定领域内的难题解决方案; - **模拟赛**:不定期组织校内选拔测试或与其他高校联合举行友谊对抗赛,增强团队协作精神的同时也锻炼心理素质。 #### 技术栈覆盖范围广泛 除了传统的数据结构和算法外,还包括但不限于以下方面: - 动态规划的应用实例解析,例如在处理分硬币问题时如何构建状态转移方程以求得最优解法。 - C/C++语言特性及其高效利用技巧,比如理解不同类型变量之间的转换机制,避免因误操作而导致不可预期的结果输出[^2]。 - 操作系统的底层原理探索,像掌握FIFO缓冲区的工作模式及相应寄存器的状态监测方法[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值