UVA - 133 The Dole Queue

版权声明:版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/YT201758501112/article/details/84765234

The Dole Queue

 UVA - 133 

题目传送门

模拟一遍过程,注:可能会选中同一个人

AC代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
int arr[maxn];
int n,m,k;
int next(int x,int step,int a)
{
	int num=0;
	while(num<a) {
		x=x+step;
		if(x==n+1) x=1;
		if(x==0) x=n;
		if(arr[x]==0) continue;
		else num++;
	}
	return x;
}
int main() 
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    //freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(0),cin.tie(0);
    while(scanf("%d %d %d",&n,&k,&m)&&n+m+k)
    {
    	int p=n,nape1=0,nape2=n+1;
    	memset(arr,1,sizeof(arr));
    	while(p) {
    		nape1=next(nape1,1,k);
    		nape2=next(nape2,-1,m);
    		printf("%3d",nape1); p--; arr[nape1]=0;
    		if(nape1!=nape2) {printf("%3d",nape2);p--;arr[nape2]=0;}
    		if(p) printf(",");
    	}
    	printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/YT201758501112/article/details/84765234
133