Description

 The Dole Queue 

In a serious attempt to downsize (reduce) the dole queue, The New National Green Labour Rhinoceros Party has decided on the following strategy. Every day all dole applicants will be placed in a large circle,
facing inwards. Someone is arbitrarily chosen as number 1, and the rest are numbered counter-clockwise up to N (who will be standing on 1's left). Starting from 1 and moving counter-clockwise, one labour official counts off k applicants, while another official
starts from N and moves clockwise, counting m applicants. The two who are chosen are then sent off for retraining; if both officials pick the same person she (he) is sent off to become a politician. Each official then starts counting again at the next available
person and the process continues until no-one is left. Note that the two victims (sorry, trainees) leave the ring simultaneously, so it is possible for one official to count a person already selected by the other official.

Input

Write a program that will successively read in (in that order) the three numbers (N, k and m; k, m > 0, 0 < N < 20) and determine the order in which the applicants are sent off for retraining. Each set of three
numbers will be on a separate line and the end of data will be signalled by three zeroes (0 0 0).

Output

For each triplet, output a single line of numbers specifying the order in which people are chosen. Each number should be in a field of 3 characters. For pairs of numbers list the person chosen by the counter-clockwise
official first. Separate successive pairs (or singletons) by commas (but there should not be a trailing comma).

Sample input

10 4 3
0 0 0

Sample output

 4  8,  9  5,  3  1,  2  6,  10,  7

where  represents a space.

/////uva好坑啊,就没输出换行就WA。
#include<iostream>
#include<iomanip>
#include<string.h>
using namespace std;
int main()
{
int n[10000],a,b,c,i,j,k;
int s,l,b1,c1;
while(cin>>a>>b>>c&&a)
{
n[0]=-9999;
l=0;b1=0,c1=0;i=1;j=a;
memset(n,0,sizeof(n));
n[0]=n[0];
s=a;
while(s)
{l--;c1=b1=0;
for(;i<=a;i++)
{
if(n[i]==0)
b1++;
if(b1==b)
{cout<<setw(3)<<i;n[i]=l;s--;break;}
if(i==a)
i=0;
}
if(s>=0)
{
for(;j>0;j--)
{
if(j==a+1)
j--;
if(n[j]==0||n[j]==l)
c1++;
if(c1==c&&n[j]!=l)
{cout<<setw(3)<<j;n[j]=l;s--;} if(j==1)
j=a+1;
if(c1==c)
{if(s!=0)
cout<<',';
if(s==0)
cout<<endl;
break;}
}
} }
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

The Dole Queue的更多相关文章

  1. UVA 133 The Dole Queue

    The Dole Queue 题解: 这里写一个走多少步,返回位置的函数真的很重要,并且,把顺时针和逆时针写到了一起,也真的很厉害,需要学习 代码: #include<stdio.h> # ...

  2. UVa133.The Dole Queue

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. uva133 The Dole Queue ( 约瑟夫环的模拟)

    题目链接: 啊哈哈,选我选我 思路是: 相当于模拟约瑟夫环,仅仅只是是从顺逆时针同一时候进行的,然后就是顺逆时针走能够编写一个函数,仅仅只是是走的方向的标志变量相反..还有就是为了(pos+flag+ ...

  4. 水题:UVa133-The Dole Queue

    The Dole Queue Time limit 3000 ms Description In a serious attempt to downsize (reduce) the dole que ...

  5. The Dole Queue UVA - 133

     In a serious attempt to downsize (reduce) the dole queue, The New National Green Labour Rhinoceros ...

  6. uva - 133 The Dole Queue(成环状态下的循环走步方法)

    类型:循环走步 #include <iostream> #include <sstream> #include <cstdio> #include <cstr ...

  7. UVA 133 The Dole Queue(报数问题)

    题意:一个长度为N的循环队列,一个人从1号开始逆时针开始数数,第K个出列,一个人从第N个人开始顺时针数数,第M个出列,选到的两个人要同时出列(以不影响另一个人数数),选到同一个人就那个人出列. 思路: ...

  8. uva 133 The Dole Queue 双向约瑟夫环 模拟实现

    双向约瑟夫环. 数据规模只有20,模拟掉了.(其实公式我还是不太会推,有空得看看) 值得注意的是两个方向找值不是找到一个去掉一个,而是找到后同时去掉. 还有输出也很坑爹! 在这里不得不抱怨下Uva的o ...

  9. 【紫书】uva133 The Dole Queue 参数偷懒技巧

    题意:约瑟夫问题,从两头双向删人.N个人逆时针1~N,从1开始逆时针每数k个人出列,同时从n开始顺时针每数m个人出列.若数到同一个人,则只有一个人出列.输出每次出列的人,用逗号可开每次的数据. 题解: ...

随机推荐

  1. UML 顺序图

    顺序图 顺序图是交互图的一种形式,它显示对象沿生命线发展,对象之间随时间的交互表示为从源生命线指向目标生命线的消息.顺序图能很好地显示那些对象与其它那些对象通信,什么消息触发了这些通信,顺序图不能很好 ...

  2. 【redis】windows

    官方网站:http://www.redis.io 百度百科:http://baike.baidu.com/view/4595959.htm?fr=aladdin windows下安装redis: 下载 ...

  3. .net 弹窗方式

    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请输入 ...

  4. mysql 创建临时节点

    use ZooKeeper; use AnyEvent; use AE; use Data::Dumper; use IO::Socket; my $zk = ZooKeeper->new(ho ...

  5. (未解决)在JSTL中,session 和 sessionScope 有什么区别 ??

    在JSP页面中,使用JSTL标签获取Session中的值并显示 为何当使用 ${session.user} 时,页面跳转后,第一次能够成功显示, 但是单击按钮重定向的时候,就获取不到了? 而使用 ${ ...

  6. 梳理一下重装sql2008R2sp1步骤

    我的电脑是这样,最早的时候装的是2005,后来公司用到2008,我就手动卸载,但是好像卸载的不够彻底,在装2008的时候,选择升级方式安装. 虽然成功了,但是在运行select @@version 时 ...

  7. ListBox控件

    主要介绍:自定义数据.绑定数据库数据 前台代码: <div> <asp:ListBox ID=" Width ="100px"> <asp: ...

  8. 开源软件实践之linux高性能服务器编程框架和选型

    很多人学习编程技术一般都通过一本编程语言的入门书籍,然后尝试做一些例子和小项目.但是这些都不能让我们深入的学习很多的编程技巧和高深技术,当然这个时候很多有经验的学习人员就会告诉大家,找一个好的开源软件 ...

  9. HDOJ 3790 双权值Dijkstra

    #include <iostream> #include <stdio.h> #include <string.h> #include <cstring> ...

  10. dll文件32位64位检测工具以及Windows文件夹SysWow64的坑(很详细,还有自动动手编程探测dll)

    阅读目录 dll文件不匹配导致数据库无法启动 究竟是System32还是SysWow64 区分dll文件32位64位的程序让我倍感迷惑 再次判断究竟是System32还是SysWow64——意想不到的 ...