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.

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 received 4 turns, while C received 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 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 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.

输出

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;
}
时间: 2024-07-29 04:29:22

SDUT 3165 Round Robina(模拟)的相关文章

SDUT3165:Round Robina(循环链表)

题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=3165 题意分析: 比赛时这题没有A真伤心,错了11遍,最后发现题意少读了一句. We note that E\'s count was irrelevant to the decision to end the game. 就是它丫的上面那句,比赛时真的是不能急着做题啊,一定要弄明白题在做,卡了三个小时就因为这个水逼题目.提供一组数据 4 5 输

SDUT 3183 (More) Multiplication(模拟)

(More) Multiplication Time Limit: 1000MS Memory limit: 65536K 题目描述 Educators are always coming up with new ways to teach math to students. In 2011, an educational software company, All Computer Math (ACM), developed an application to display products

hdu 5640 King&#39;s Cake(模拟)

Problem Description It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size n×m(1≤n,m≤10000) . The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut

loj rounds 补题

LibreOJ β Round ZQC 的树列 考虑原序列中的所有子序列中,美观值最大的一定是原序列. 那么这些子序列美观度与原序列相同的充要条件是包含每个最值点. 由于我们要构造一个特征值为\(k\)的序列.其实只用\(0, 1, 2\)三种元素就能构造.构造的序列一定是一段0(,一段1),一段2(,一段1),一段0(,一段1)... 考虑一段长度为\(l\)的连续1的贡献为\(2 ^ l\),一段长度为\(l\)的连续0或2的贡献为\(2 ^ l - 1\).相当于把\(k\)分解成这种数的

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

LibreOJ #514. 「LibreOJ β Round #2」模拟只会猜题意

二次联通门 : LibreOJ #514. 「LibreOJ β Round #2」模拟只会猜题意 /* LibreOJ #514. 「LibreOJ β Round #2」模拟只会猜题意 本想打个暴力找找规律 结果交上去就A了... 读入所有数 处理出前缀和 然后枚举区间长度 处理处1~n的答案 后O(1)查询即可 复杂度O(n^2 + m) */ #include <iostream> #include <cstring> #include <cstdio> voi

Codeforces Round #259 (Div. 2) (简单模拟实现题)

题目链接:http://codeforces.com/problemset/problem/454/A A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine

Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模拟 枚举

Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模拟  枚举 题意 一个红绿灯 按逆时针方向一次给出各个路口的左转,直行,右转,以及行人车道让你判断,汽车是否有可能撞到行人 注意 当前车道的左转有可能撞到别的车道的行人的 题解 一大堆特判 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring&g

SDUT OJ 图练习-BFS-从起点到目标点的最短步数 (vector二维数组模拟邻接表+bfs , *【模板】 )

图练习-BFS-从起点到目标点的最短步数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 在古老的魔兽传说中,有两个军团,一个叫天灾,一个叫近卫.在他们所在的地域,有n个隘口,编号为1..n,某些隘口之间是有通道连接的.其中近卫军团在1号隘口,天灾军团在n号隘口.某一天,天灾军团的领袖巫妖王决定派兵攻打近卫军团,天灾军团的部队如此庞大,甚至可以填江过河.但是巫妖王不想付出不必要的代价,他想知道在不修建任何通道的前提下,部队是否