您的位置:首页 > 产品设计 > UI/UE

UvaOJ 133 - The Dole Queue

2013-12-29 15:01 288 查看
这是一道循环队列的简单题,不过我愣是做了三个小时……英语不好,地动山摇。惩罚我把题目翻译一遍……

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: