SDUT 3165 Round Robina (simulation)

Source: Internet
Author: User

SDUT 3165 Round Robina (simulation)

Round Robina Time Limit: 1000 ms Memory limit: 65536 K any questions? Click Here ^_^ 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.

Player A B C D E
Count 0 0 0 0 0

Beginning with A, 17 turns are taken. B will have 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 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.

Player A C D E
Count 4 3 3 3

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

Player A C D E
Count 8 8 7 7

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

Player A D E
Count 8 7 7



The next 17 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 two remaining players have the same count of 13. therefore, the game ends. (We note that E \'s count was irrelevant to the describe to end the game .)

 

Enter The input will contain in one or more datasets. each dataset will be described with a single line containing two integers, N and T, where N (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 1090 20
Sample output
2 135 345 1
Message Source: 2013 ACM MId-Central Reginal Programming Contest (MCPC2013) sample program

#include
 
  #include#include
  
   #include
   
    #include
    
     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
     
    
   
  
 

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.