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个 ...
随机推荐
- 【C#进阶系列】05 基元类型、引用类型和值类型
基元类型和FCL类型 FCL类型就是指Int32这种类型,这是CLR支持的类型. 而基元类型就是指int这种类型,这是C#编译器支持的,实际上在编译后,还是会被转为Int32类型. 而且学过C的朋友 ...
- 【jQuery基础学习】02 jQuery的DOM操作
DOM操作分为3个方面: DOM Core 任何一种支持DOM Core的语言都可以使用它,比如getElementById就是DOM Core操作 HTML-DOM 只能用来处理web文档 ...
- SqlServer常用语句参考
1.SQL SERVER中如何使用SQL 语句复制表结构: select * into 新表 from 旧表 where 1=2 把“旧表”的表结构复制到“新表”,1=2不复制数据,如果要复制数据,就 ...
- 从几篇文字得到关于web app开发的性能问题的答案
1. http://blogs.adobe.com/creativecloud/are-mobile-web-apps-slow/ 2. http://software.intel.com/zh-cn ...
- $(document).ready()即$()方法和window.onload方法的比较
以浏览器装载文档为例,我们都知道在页面完毕后,浏览器会通过JavaScript为DOM元素添加事件.在常规的JavaScript代码中,通常使用window.onload方法,而在jQuery中,使用 ...
- owl-carousel轮播插件的使用
插件github地址:https://github.com/OwlFonk/OwlCarousel: 插件官网演示地址:http://owlgraphic.com/owlcarousel/: 1.选择 ...
- iOS 抽象工厂模式
iOS 抽象工厂模式 什么是抽象工厂模式 简单了解一下 按照惯例,我们先了解一下什么是抽象工厂模式.抽象工厂模式和工厂方法模式很相似,但是抽象工厂模式将抽象发挥的更加极致,是三种工厂模式中最抽象的一种 ...
- C++语言-02-函数
普通函数 C++是在C语言的基础上增加了面向对象特性的语言,是C语言的超集 C++中的普通函数与C语言中的普通函数具有类似的性质.请参照以下博客:C语言-04-函数 与类相关的函数 C是一种OOP语言 ...
- 小波说雨燕 第三季 构建 swift UI 之 UI组件集-视图集(三)Activity Indicators视图 学习笔记
当我们应用程序执行一个比较耗时的操作,我们需要给用户一个提示,那么这个提示比较好的方式方法呢就是 进度条 或者 一个齿轮转.我们就需要Activity Indicators组件 Indicato ...
- URL、表单数据、IP等处理类
<?php class ev { public $cookie; public $post; public $get; public $file; public $url; public $G; ...