The Dole Queue

Source: Internet
Author: User

The Dole QueueTime limit:MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit

cid=1036#status//a/0 "class=" Ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only "style=" Font-family:verdana,arial,sans-serif; Font-size:1em; border:1px solid RGB (211,211,211); Color:rgb (85,85,85); Display:inline-block; position:relative; padding:0px; Margin-right:0.1em; Zoom:1; overflow:visible; Text-decoration:none ">Status

Description


The Dole Queue

In a serious attempt to downsize (reduce) The dole queue, the New national Green Labour Rhinoceros Party have decided on th E following strategy. Every day all dole applicants'll be placed in a large circle, facing inwards. Someone is arbitrarily chosen as number 1, and the rest was numbered counter-clockwise up to N (who'll be standing on 1 ' s left). Starting from 1 and moving counter-clockwise, one Labour official counts off K applicants, while another official starts F Rom N and moves clockwise, counting m applicants. The Who is chosen is 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 on the next available person and the process continues until no-one are left. Note that the both victims (sorry, trainees) leave the ring simultaneously, so it was possible for one official to count a P Erson already selected by the other official.

Input

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

Output

For each triplet, output a single line of numbers specifying the order in which people is chosen. Each number should is in a field of 3 characters. For pairs of numbers lists 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 30) 0 0

Sample Output

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

Where represents a space.


UVA good pit Ah, there is no output to change the line on 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;}


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

The Dole Queue

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.