标签:
入门题...
#include <cstdio> #include <iostream> #include <cstring> using namespace std; int n,k,m,num; int a[25]; int find(int pos,int x,int m) { while(m--) { pos=(pos+x+n-1)%n+1; while(a[pos]) pos=(pos+x+n-1)%n+1; //cout<<pos<<endl; } return pos; } int main() { while(~scanf("%d%d%d",&n,&k,&m)&&(n+k+m)) { memset(a,0,sizeof(a)); num=n; int p1=n,p2=1; while(num) { p1=find(p1,1,k); p2=find(p2,-1,m); printf("%3d",p1); num--; if(p1!=p2) { printf("%3d",p2); num--; } a[p1]=a[p2]=1; if(num) printf(","); } puts(""); } return 0; }
标签:
原文地址:http://www.cnblogs.com/nicetomeetu/p/5414927.html