首页 > 学院 > 开发设计 > 正文

UVa133 - The Dole Queue

2019-11-08 02:37:12
字体:
来源:转载
供稿:网友
//UVa133 - The Dole Queue#include<cstdio>#define maxn 25using namespace std;int n, k, m, a[maxn];//p为初位置,逆时针走t步,d为-1时顺时针走,返回新位置int go(int p, int d, int t){    while(t--){        do{ p = (p+d+n-1)%n+1; }while(a[p] == 0);    }    return p;}int main(){    while(scanf("%d%d%d", &n, &k, &m) == 3 && n){        for(int i = 1; i <= n; i++) a[i] = i;        int left = n;        int x = n, y = 1;        while(left--){            x = go(x, 1, k);            y = go(y, -1, m);            PRintf("%3d", x); left--;            if(y != x){ printf("%3d", y); left--;}            a[x] = a[y] = 0;            if(left) printf(",");        }        printf("/n");    }    return 0;}/*10 4 34  8,  9  5,  3  1,  2  6, 10,  7,*/
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表