uva133-S.B.S.
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.
----------------------------------我是分割线--------------------------------------------
这道题简单,上代码:
// UVa133 The Dole Queue
#include<cstdio>
#define maxn 25
int n, k, m, a[maxn];
int go(int p, int d, int t) {
while(t--) {
do {p=(p+d+n-)%n+;} while(a[p] == );
}
return p;
} int main() {
while(scanf("%d%d%d", &n, &k, &m) == && n) {
for(int i = ; i <= n; i++) a[i] = i;
int left = n;
int p1 = n, p2 = ;
while(left) {
p1 = go(p1, , k);
p2 = go(p2, -, m);
printf("%3d", p1); left--;
if(p2 != p1) { printf("%3d", p2); left--; }
a[p1] = a[p2] = ;
if(left) printf(",");
}
printf("\n");
}
return ;
}
uva133-S.B.S.的更多相关文章
- uva133 救济金发放
#include<stdio.h> #define maxn 20 ], n; int go( int p,int d,int t ) {// printf("a[%d]=%d\ ...
- UVa133.The Dole Queue
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva133 The Dole Queue ( 约瑟夫环的模拟)
题目链接: 啊哈哈,选我选我 思路是: 相当于模拟约瑟夫环,仅仅只是是从顺逆时针同一时候进行的,然后就是顺逆时针走能够编写一个函数,仅仅只是是走的方向的标志变量相反..还有就是为了(pos+flag+ ...
- 【紫书】uva133 The Dole Queue 参数偷懒技巧
题意:约瑟夫问题,从两头双向删人.N个人逆时针1~N,从1开始逆时针每数k个人出列,同时从n开始顺时针每数m个人出列.若数到同一个人,则只有一个人出列.输出每次出列的人,用逗号可开每次的数据. 题解: ...
- UVA133
减少领取救济金排队的长度是一个严重的问题,The New National Green Labour RhinocerosParty (这个党派)依据如下规则.每天来领取救济金的人排成一个大圆环.任选 ...
- 救济金发放(UVa133)
题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...
- UVA133 - The Dole Queue【紫书例题4.3】
题意: n个人围成个圆,从1到n,一个人从1数到k就让第k个人离场,了另一个人从n开始数,数到m就让第m个人下去,直到剩下最后一个人,并依次输出离场人的序号. 水题,直接上标程了 #include&l ...
- 算法习题---4.3救济金发放(UVa133)
一:题目 (n< )个人站成一圈,逆时针编号为1~n.有两个官员,A从1开始逆时针数,B从n开始顺时针数.在每一轮中,官员A数k个就停下来,官员B数m个就停下来(注意有可能两个官员停在同一个人上 ...
- 4_3 救济金发放(UVa133)<子过程/函数设计>
为了缩短领救济品的队伍,NNGLRP决定了以下策略:每天所有来申请救济品的人会被放在一个大圆圈,面朝里面.标明一个人为编号1号,其他的就从那个人开始逆时针开始编号直到N.一个官员一开始逆时针数,数k个 ...
随机推荐
- Web Service学习小结(概念性回忆)-希望你们会喜欢
Web Service的出现带来了很多系统工程直接相互的调用.无疑让代码的隐藏得到了好的封装. Web Service 它的主要的组成要素: SOAP:(Simple Object Access P ...
- iis到w3wp的数据流及工作原理
HTTP.sys->IO线程-CLR线程池中的worker线程处理 IO线程只负责把请求交给Worker线程或者放入进程池级别的队列,然后又去HTTP.SYS的队列中处理其它的请求
- Protocol Buffers动态消息解析
http://www.searchtb.com/2012/09/protocol-buffers.html http://www.cnblogs.com/jacksu-tencent/p/344731 ...
- fibonacci封闭公式及矩阵连乘
Description The Fibonacci sequence is the sequence of numbers such that every element is equal to th ...
- 默认选中ComboBox的某一项
如: 让它选中“统计今天”(控件Name为cobListTime) 方法: 1.cobListTime.Text = cobListTime.Items[0].ToString();//默认选中第一个 ...
- Android 计算布局背景的透明度
1.#ff000000 此为16进制颜色代码,前2位ff为透明度,后6位为颜色值(000000为黑色,ffffff为白色,可以用ps等软件获取). 2.透明度分为256阶(0-255),计算机上用16 ...
- android在Data目录内置可删除的APP
一.准备工作:make_ext4fs.mkuserimg.sh.simg2img,把它们跟要修改的 .img.ext4(或.img)文件放置到同一个目录下 二.转换源文件为img格式( .img则略过 ...
- HBase权威指南环境配置
出处:http://wuyudong.com/1958.html 系统采用ubuntu-14.04,64bit 1.安装git sudo apt-get install git 出现下面错误:Err ...
- NavigationController的使用整理
1.设置NavigationBar的背景色: self.navigationController.navigationBar.barTintColor = [UIColor redColor]; 2. ...
- OC小实例关于init方法不小心的错误
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...