题目链接:http://acm.whu.edu.cn/land/problem/detail?problem_id=1462
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<stack>
#include<queue>
using namespace std;
int main()
{
stack<int>a,b,c;
queue<int>p,q;
int ncases,n,x,y,i,count=1;
scanf("%d",&ncases);
while(ncases--)
{
while(!a.empty()) {a.pop();}//清空
while(!b.empty()) {b.pop();}
while(!c.empty()) {c.pop();}
while(!p.empty()) {p.pop();}
while(!q.empty()) {q.pop();}
scanf("%d %d %d",&n,&x,&y);
for(i=1;i<=n;i++)//Initial
{a.push(i);}
while(c.size()!=n)
{
for(i=1;i<=x;i++)//A->B
{
if(a.empty()) {break;}
b.push(a.top());
a.pop();
}
int alen=a.size();//A RESERVE
for(i=1;i<=alen;i++)
{
p.push(a.top());
a.pop();
}
for(i=1;i<=alen;i++)
{
a.push(p.front());
p.pop();
}
for(i=1;i<=y;i++)//B->C
{
if(b.empty()) {break;}
c.push(b.top());
b.pop();
}
int blen=b.size();
for(i=1;i<=blen;i++)//B RESERVE
{
q.push(b.top());
b.pop();
}
for(i=1;i<=blen;i++)
{
b.push(q.front());
q.pop();
}
}
printf("Case %d: ",count++);
for(i=1;i<=n;i++)
{
if(i<n)
{
printf("%d ",c.top());
c.pop();
}
if(i==n)
{
printf("%d\n",c.top());
c.pop();
}
}
}
return 0;
}