hdu 12490 Round Robin

Round Robin
Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:65536KB
Total submit users: 36, Accepted users: 28
Problem 12940 : No special judgement
Problem description

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:


PlayerA BCDE
Count4 4333

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:


PlayerA CDE
Count8 877

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:

PlayerAD E
Count1313 13

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.)



Input

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.


Output

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.


Sample Input
5 17
7 10
90 2
0
Sample Output
2 13
5 3
45 

每轮给n个人发t个东西  一个人一个人的发  一个一个的发  每轮中发到最后一个的被淘汰

如果发了m个之后剩下的不够这一回合中每个人都能拿到一个就从上次被淘汰那个人的位置继续发剩下的 每人发一个

直到剩下的人所拥有东西的数量都是一样的为止

主要是要记录下被淘汰人的序号   其他的模拟整个过程就可以了   被淘汰人之后的要向前移动  

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>

#define eps 1e-8
#define op operator
#define MOD  10009
#define MAXN  100100

#define FOR(i,a,b)  for(int i=a;i<=b;i++)
#define FOV(i,a,b)  for(int i=a;i>=b;i--)
#define REP(i,a,b)  for(int i=a;i<b;i++)
#define REV(i,a,b)  for(int i=a-1;i>=b;i--)
#define MEM(a,x)    memset(a,x,sizeof a)
#define ll __int64

using namespace std;

int num[110],vis[110];

int main()
{
//freopen("ceshi.txt","r",stdin);
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)   break;
        int t;
        scanf("%d",&t);
        MEM(vis,0); MEM(num,0);
        int x=0;
        while(1)
        {
            for(int i=0;i<n;i++)
                num[i]+=(t/n);
            for(int i=0;i<(t%n);i++)
            {
                num[x]++;
                x++;
                x%=n;
            }
            n--;
            if(x!=0)
            {
                for(int i=x-1;i<n;i++)
                    num[i]=num[i+1];
            }
            if(x==0)  x=n;
            else x--;
            int flag=0;
            for(int i=0;i<n-1;i++)
            {
                if(num[i]!=num[i+1])
                {
                    flag=1; break;
                }
            }
            if(n==1||flag==0)
            {
                printf("%d %d\n",n,num[0]);
                break;
            }
        }

    }
    return 0;
}


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值