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. Chapter 9 原型模式

    原型模式:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 简单的说就是clone一个对象实例.使得clone出来的copy和原有的对象一模一样. 插一个简单使用clone的例子,如果 ...

  2. Python基础1:一些小知识汇总

    一.#!usr/bin/env python 脚本语言的第一行,指定执行脚本的解释器. #!/usr/bin/python 是告诉操作系统执行这个脚本的时候,调用/usr/bin下的python解释器 ...

  3. SolrCloud简介

    原文地址:http://www.chepoo.com/solrcloud-introduction.html 一.简介 SolrCloud是Solr4.0版本以后基于Solr和Zookeeper的分布 ...

  4. JAVA爬虫 WebCollector

    JAVA爬虫 WebCollector 爬虫简介: WebCollector是一个无须配置.便于二次开发的JAVA爬虫框架(内核),它提供精简的的API,只需少量代码即可实现一个功能强大的爬虫. 爬虫 ...

  5. 基于visual Studio2013解决算法导论之020单链表

     题目 单链表操作 解决代码及点评 #include <iostream> using namespace std; struct LinkNode { public: LinkNo ...

  6. Mysql 启动失败 报错 1067

    Mysql装好后,重启电脑第二次发现服务无法启动.提示如下: ------------------------ MySQL 服务无法启动. 系统出错. 发生系统错误 1067. 进程意外终止. --- ...

  7. Java CopyOnWriteArrayList分析

    CopyOnWriteArrayList是一种线程安全的ArrayList,顾名思义,它会利用写时拷贝技术,它对共享对象做仅仅读操作的时候,大家都用一个共享对象,假设有可变的操作时,就会复制一份出来, ...

  8. Eclipse 和 MyEclipse控制台console不停的自动跳动,跳出来解决方案

    有时候Eclipse启动,控制台console不会自动跳出来,需要手工点击该选项卡才行,按下面的设置,可以让它自动跳出来(或不跳出来):由二种方法: 一.windows  ->   prefer ...

  9. STLport在vc6中的集成

    STLport的下载 http://sourceforge.net/projects/stlport/ STLport的编译 * 试验环境 : win7x64sp1 + vc6sp6* 打开控制台窗口 ...

  10. 用来解析,格式化,存储和验证国际电话号码:libphonenumber

    用来解析,格式化,存储和验证国际电话号码:libphonenumber libphonenumber是Google的公共Java.C++和Javascript库用来解析,格式化,存储和验证国际电话号码 ...