Sdut 3165 Round Robina (Analog)

Source: Internet
Author: User

Round Robina Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^ Title 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 is taken. After a round, the player just had a turn are eliminated from the game. If The remaining players has 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 is 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 Coun TS initially zero.


player A b c d e
count 0 0 0 0 0

beginning with A, turns is Taken. B would has taken the last of those turn, leaving our counts as follows:


player A b c d e
count 4 4 3 3 3

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

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

" TR style= "padding:0px; margin:0px ">

player A c d e
count 4 3 3 3

after + turns starting With C, we find is A, D and E received 4 turns, while C received 5 turns, including the last:

" TR style= "padding:0px; margin:0px ">

player A c d e
count 8 8 7 7

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


Player A D E
Count 8 7 7



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


Player A D E
Count 13 13 13


Then E leaves.


Player A D
Count 13 13

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

Enter the input would contain one or more datasets. Each dataset is described with a, containing, integers,NandT, whereN(2≤N≤100) is the initial number of players, andT(2≤T≤100) is the number of turns after which the player with the most recently completed turn leaves. Following the last dataset was a line containing only 0. Output there is one line of output for each dataset, containing-numbers,PandC. At the time the game endsPIs the number of players this remain in the game andCIs the common count they all has. Sample input
5 17 7) 1090 20
Sample output
2 135 345 1
Tip Source of ACM mid-central reginal programming Contest (MCPC2013) sample program

#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;}


Sdut 3165 Round Robina (Analog)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.