| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
怒贴代码,被这题坑死了,注意a和b可能在同一堆,甚至a可能等于b#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
using namespace std;
const int N = 30;
const int X = 26;
int st[N][N];
int pos[N],lv[N],num[N];
void init(int n)
{
for(int i=0;i<N;i++)
lv[i]=1,pos[i]=i,num[i]=1,st[i][1]=i;
}
void out(int n)
{
for(int i=0;i<n;i++){
printf("%d:",i);
for(int j=1;j<=num[i];j++)
printf(" %d",st[i][j]);
printf("\n");
}
}
void move(int a,int b)
{
st[b][++num[b]]=st[a][num[a]--];
pos[st[b][num[b]]]=b;
lv[st[b][num[b]]]=num[b];
}
void clear(int a)
{
for(int i=num[pos[a]];i>lv[a];i--)
move(pos[a],st[pos[a]][i]);
}
void move2(int a,int b)
{
for(int i=num[pos[a]];i>=lv[a];i--)
move(pos[a],b);
}
void pile(int a,int b)
{
int p=pos[b];
move2(a,X);
move2(st[X][2],p);
}
int main()
{
int n,a,b;
char x[100],y[100];
scanf("%d",&n);
init(n);
while(scanf("%s",x)==1&&x[0]!='q'){
scanf("%d %s %d",&a,y,&b);
if(x[0]=='m')clear(a);
if(y[1]=='n')clear(b);
pile(a,b);
out(n);
}
out(n);
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator