问题类型:循环数组。
03pie’s solution for [UVA-133]:
#include<bits/stdc++.h>//包含所有头文件
using namespace std;#define ms(s) memset(s,0,sizeof(s))typedef unsigned long
#define maxn 20int que[maxn];int ans(int start,int times,int d,int n)
{int p=start;while(times--){do{p=(p+d-1+n)%n+1;}while(que[p]==0);}return p;
}
int main(){// freopen("F://inp.txt","r",stdin);int n,a,b;while(scanf("%d%d%d",&n,&a,&b)!=EOF&&n){int A,B,sum=n;int f=1,l=n;for(int i=1;i<=n;i++){que[i]=i;} while(sum){A=ans(l,a,1,n);B=ans(f,b,-1,n);// printf("\nA=%d B=%d",A,B);printf("%3d",que[A]);que[A]=0;if(A==B){sum--; }else{printf("%3d",que[B]);sum-=2; que[B]=0;}if(sum) printf(",");l=A;f=B;}printf("\n");}return 0;
}