SDUT 3165 Round Robina(模拟)

Round Robina

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

Suppose that N players sit in order and take turns in a game, with the first person following the last person, to continue in cyclic order. While doing so, each player keeps track of the number of turns he or she has taken. The game consists of rounds, and in each round T turns are taken. After a round, the player who just had a turn is eliminated from the game. If the remaining players have all had the same number of turns, the game ends. Otherwise, they continue with another round of T moves, starting with the player just after the one who was most recently eliminated.

As an example, assume we begin a game with N=5 and T=17, labeling the players in order as A, B, C, D, and E, with all counts initially zero.


PlayerABCDE
Count00000

Beginning with A, 17 turns are taken. B will have taken the last of those turn, leaving our counts as follows:


PlayerABCDE
Count44333

Suppose that after every 17 turns, the player who just had a turn is eliminated from the game. All remaining players then compare their counts. If all of those counts are equal, everyone has had a fair number of turns and the game is considered completed. Otherwise, they continue with another round of 17 moves starting with the player just after the one who was most recently eliminated.

Continuing with our example, B will leave the game, and the next turn will be for C.


PlayerACDE
Count4333

After 17 more turns starting with C, we find that A, D and E received 4 turns, while C received 5 turns, including the last:


PlayerACDE
Count8877

Then C leaves, and since the remaining counts are not all the same, a new round beings with D having the next turn.


PlayerADE
Count877



The next 17 turns start with D and end with E.   A adds 5 turns, while D and E add 6:


PlayerADE
Count131313


Then E leaves.


PlayerAD
Count1313

At this point, notice that the two remaining players have the same count of 13. Therefore, the game ends. (We note that E\'s count was irrelevant to the decision to end the game.)

 

 

输入

 The input will contain one or more datasets.  Each dataset will be described with a single line containing two integers,  N and  T, where  (2 ≤  N ≤ 100) is the initial number of  players, and  T (2 ≤  T ≤ 100) is the number of turns after which the player with the most recently completed turn leaves.  Following the last dataset is a line containing only 0.
 

输出

 There is one line of output for each dataset, containing two numbers,  p and  c.  At the time the game ends  p is the number of players that remain in the game and  c is the common count they all have.

示例输入

5 17 
7 10
90 2
0

示例输出

2 13
5 3
45 1

提示

 

来源

2013 ACM MId-Central Reginal Programming Contest(MCPC2013)

示例程序

 


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int n,m;

struct node
{
    int x;
    int pf;
}q[10010];

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        if(n == 0)
        {
            break;
        }
        scanf("%d",&m);
        for(int i=0;i<=n;i++)
        {
            q[i].x = 0;
            q[i].pf = 0;
        }
        int pn = n;
        int flag = 0;
        int pi = 0;
        while(flag == 0)
        {
            int pt = m/pn;
            int pm = m%pn;
            for(int i=0;i<n;i++)
            {
                if(q[i].pf == 0)
                {
                    q[i].x += pt;
                }
            }
            int pj = 0;
            while(pj<pm)
            {
                pi = pi%n;
                if(q[pi].pf == 0)
                {
                    q[pi].x = q[pi].x + 1;
                    pj++;
                    if(pj == pm)
                    {
                        break;
                    }
                }
                pi = pi + 1;
            }
            if(pm == 0)
            {
                while(q[pi].pf == 1)
                {
                    pi--;
                }
            }
            q[pi].pf = 1;
            pn--;
            int kk = -1;
            int cnt = 0;
            for(int i=0;i<n;i++)
            {
                if(q[i].pf == 0 && kk == -1)
                {
                    kk = q[i].x;
                }
                if(q[i].pf == 0 && q[i].x == kk)
                {
                    cnt++;
                }
            }
            if(cnt == pn)
            {
                printf("%d %d\n",cnt,kk);
                flag = 1;
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶孤心丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值