UvaOJ 133 - 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.


在一次减少救济金的队伍的尝试中,有一个什么什么组织决定用如下的策略。每天所有的救济金的申请人要站成一个大圈,面向里面。有一个人被随机的选成1号,剩下的被逆时针编号至N(N号将站在1号的左边)。一个工作人员从1号开始逆时针数k个申请人,另一个工作人员从N开始顺时针数m个申请人。两个被选中的申请人将被送走进行训练(题目这里是什么意思……)如果两个工作人员选中了同一个,他(她)将被送去成为政治家(题目这里又让我凌乱了……)。然后每一个工作人员再从下一个可用的人开始数,这个过程将持续到没有人留下为止。注意两个受害者(抱歉,接受训练的人)同时离开圈子,所以一个工作人员算数的时候算上另一个工作人员已经选了的人是有可能的。

呃~~标上蓝色的是我的注释,其他的都是题目里面翻译过来的。英语水平也就这程度了……

程序倒是很简单,不过还是改了N次……

代码奉上

#include<iostream>
#include<stdio.h>
#include<iomanip>
using namespace std;
int A[20];
int main(){
	int m,n,k;
	while(scanf("%d%d%d",&n,&m,&k)&&m&&n&&k){
		for(int i=1;i<=n;++i){
			A[i]=1;
		}
		int tot=0;
		int b,c;
		b=1;c=n;
		while(tot<n){
//			cout<<endl;
//			for(int i=1;i<=n;++i){cout<<A[i]<<' ';}
//			cout<<endl;
//			cout<<"tot="<<tot<<endl;
			for(int i=1;i<=m;){//ÄæʱÕë 
//				cout<<"test~~~"<<b<<' '<<i<<endl;
				if(A[b]){
					b++;
					i++;
				}
				else b++;
				if(b==n+1)b=1;
			}
			b--;
			if(b==0)b=n;
			for(int i=1;i<=k;){//˳ʱÕë 
				if(A[c]){
					i++;
					c--;
					if(c==0){
						c=n;
					}
				}
				else {c--;if(c==0)c=n;}
			}
			c++;
			if(c==n+1)c=1;
			A[c]=0;
			A[b]=0;
			if(c!=b)
			{
				cout<<setw(3)<<b;
				cout<<setw(3)<<c;
				tot+=2;}
			else {
				cout<<setw(3)<<b;tot+=1;}
			if(tot<n)cout<<",";
		}
		cout<<endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
用C++编写程序,实现以下问题2、题目ID Codes(POJ1146) Time Limit: 1000MS Memory Limit: 10000K 描述: It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In order to exercise greater control over its citizens and thereby to counter a chronic breakdown in law and order, the Government decides on a radical measure--all citizens are to have a tiny microcomputer surgically implanted in their left wrists. This computer will contains all sorts of personal information as well as a transmitter which will allow people's movements to be logged and monitored by a central computer. (A desirable side effect of this process is that it will shorten the dole queue for plastic surgeons.) An essential component of each computer will be a unique identification code, consisting of up to 50 characters drawn from the 26 lower case letters. The set of characters for any given code is chosen somewhat haphazardly. The complicated way in which the code is imprinted into the chip makes it much easier for the manufacturer to produce codes which are rearrangements of other codes than to produce new codes with a different selection of letters. Thus, once a set of letters has been chosen all possible codes derivable from it are used before changing the set. For example, suppose it is decided that a code will contain exactly 3 occurrences of a', 2 of b' and 1 of c', then three of the allowable 60 codes under these conditions are: abaabc abaacb ababac These three codes are listed from top to bottom in alphabetic order. Among all codes generated with this set of characters, these codes appear consecutively in this order. Write a program to assist in the issuing of these identification codes. Your program will accept a sequence of no more than 50 lower case letters (which may contain repeated characters) and print the successor code if one exists or the message No Successor' if the given code is the last in the sequence for that set of characters. 输入: Input will consist of a series of lines each containing a string representing a code. The entire file will be terminated by a line consisting of a single #. 输出: Output will consist of one line for each code read containing the successor code or the words 'No Successor'. 样例输入 abaacb cbbaa # 样例输出 ababac No Successor
最新发布
05-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值