HNU Round Robin (约瑟夫)

Round Robin
Time Limit: 2000ms, Special Time Limit:5000ms,
Memory Limit:65536KB
Total submit users: 37, Accepted users:
30
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.

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

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
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 10
90 2
0
Sample Output
2 13
5 3
45 1
Problem Source
ACM Mid-Central Programming Competition 2013

#include<stdio.h>
typedef struct nnnn
{
    int count;
    struct nnnn *next;
}node;
int MAX(int a,int b){return a>b?a:b;}
int MIN(int a,int b){return a<b?a:b;}
node *head;
void builde(int n)
{
    node *p;
    head=new node;
    head->count=0; head->next=head;
    for(int i=2;i<=n;i++)
    {
        p=new node; p->count=0;
        p->next=head->next; head->next=p;
    }
}
void find(int t,int n)
{
    int max=0,min=9999999;
    while(max!=min)
    {
        int i=1;
        head->count++;
        if(t==1)
        {
            while(i<n) head=head->next;
        }
       else while(i<t-1)
        {
             i++; head=head->next; head->count++;
        }
        head->next=(head->next)->next; n--;
        max=0,min=9999999;
        for(i=1;i<=n+1;i++)
        {
            if(max<(head->count))max=head->count;
            if(min>(head->count))min=head->count;
            head=head->next;
        }
    }
    printf("%d %d\n",n,max);
}
int main()
{
    int n,t,st;
    while(scanf("%d",&n)>0&&n)
    {
        scanf("%d",&t);
        builde(n);
        find(t,n);
    }
}
时间: 2024-12-26 04:24:31

HNU Round Robin (约瑟夫)的相关文章

Round robin

http://www.computerhope.com/jargon/r/rounrobi.htm Round robin Round robin is a method of distributing multiple sources to one of the many devices or connections. For example, a company may have multiple servers that are identical to each other. When

round robin schedule(循环日程表)

the source of the article:https://github.com/Fibird/Round-robin-schedule #include <iostream>#include <math.h> #define N 3 using namespace std; int main(){ int sche = pow(2.0, N); //the number of athlete int **arr = new int*[sche]; int bw = 1;

MIT JOS # Round&#173;Robin Scheduling#

MIT JOS # Round-Robin Scheduling# 下面是MIT JOS里 round-robin调度策略的实现. 在 kern/sched.c里面 下面的截图来自<<Modern Operating system>> (以前搬过的砖也是有好处的哇-) 结合代码就能够很形象的理解Round-robin. 每当我们调用sched_yeild()的时候,我们就打算让当前进程让出CPU了. 于是把 idle = thiscpu->cpu_env; 我们每次都让出当前

Set the Round Robin IOPS limit from 1000 to 1

https://kb.vmware.com/s/article/2069356 http://www.enterprisedaddy.com/2017/02/set-round-robin-iops-limit-default-1000-1-using-powercli/ 1,Query the paths of the LUNesxcli storage nmp path list --device naa.60000971111492600622233032393333 2,Set the

操作系统,时间片轮转算法的C语言实现Round Robin

1 #include "windows.h" 2 #include <conio.h> 3 #include <stdlib.h> 4 #include <fstream.h> 5 #include <io.h> 6 #include <string.h> 7 #include <stdio.h> 8 9 void Create_ProcInfo(); // 建立进程调度需要的数据 10 void Display_

Set VM RDM disk to Round Bobin and set IOPS path to 1

KB Related to IOPS setting Adjusting Round Robin IOPS limit from default 1000 to 1 (2069356) https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2069356 To adjust the IOPS parameter from the default 1000

Linux双网卡绑定bond0详解

1 什么是bond 网卡bond是通过多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在生产场景中是一种常用的技术.Kernels 2.4.12及以后的版本均供bonding模块,以前的版本可以通过patch实现.可以通过以下命令确定内核是否支持 bonding: [[email protected] network-scripts]#cat /boot/config-2.6.32-573.el6.x86_64 |grep -i bonding CONFIG_BONDING=

V 11 FastDFS

一.概念: https://github.com/happyfish100/fastdfs FastDFS is an open source high performance distributed file system (DFS). It's major functions include: file storing, file syncing and file accessing, and design for high capacity and load balance. https:

负载均衡算法的几种常用方案

总结下负载均衡的常用方案及适用场景 轮询调度 以轮询的方式依次请求调度不同的服务器:实现时,一般为服务器带上权重:这样有两个好处: 针对服务器的性能差异可分配不同的负载: 当需要将某个结点剔除时,只需要将其权重设置为0即可: 优点:实现简单.高效:易水平扩展: 缺点:请求到目的结点的不确定,造成其无法适用于有写的场景(缓存,数据库写) 应用场景:数据库或应用服务层中只有读的场景: 随机方式 请求随机分布到各个结点:在数据足够大的场景能达到一个均衡分布: 优点:实现简单.易水平扩展: 缺点:同Ro