Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

怒贴代码,被这题坑死了,注意a和b可能在同一堆,甚至a可能等于b

Posted by hassenio at 2012-07-15 15:45:19 on Problem 1208
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator