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

WA,大家可以互相交流一下,也帮我找找错,自认为方法还可以,另附几组测试数据

Posted by XBWer at 2012-09-21 16:48:25 on Problem 3344
#include<iostream>
using namespace std;

char map[10][10];
char map1[10][10];
char opr[10];
int vst[10][10];
int vst1[10][10];
int sx,sy;

int dir[4][2]={
	0,1,            //right
	-1,0,            //up
	0,-1,           //left
	1,0            //down
};

bool check(int x,int y)
{
	if(x>=0&&x<8&&y>=0&&y<8)
		return true;
	return false;
}

void fun_move(int ndir,int k)
{
	int i,j;
	int kk=k;
	int x=sx,y=sy;
	for(i=x,j=y;check(i,j);i+=dir[ndir][0],j+=dir[ndir][1])
	{
		int tx=i+k*dir[ndir][0];
		int ty=j+k*dir[ndir][1];
		if(i==x&&j==y)
			sx=tx,sy=ty;
		if(!check(tx,ty)&&i==x&&j==y)
		{
			for(i=x,j=y;check(i,j);i+=dir[ndir][0],j+=dir[ndir][1])
			{
				vst[i][j]=1;
				map[i][j]='.';
			}
			sx=i-=dir[ndir][0];
			sy=j-=dir[ndir][1];
			break;
		}
		else
		{	
			if(k<=0)
				break;
			if(map1[i][j]=='.'&&!(x==i&&y==j))
				k--;
			else if(check(tx,ty))
			{
				if(vst[i][j])
					map[tx][ty]=map[i][j];
				else
					map[tx][ty]=map1[i][j];
				vst1[tx][ty]=1;
				if(!vst1[i][j])
					map[i][j]='.';
				vst[i][j]=1;
			}
			else if(!check(tx,ty))
			{
				if(!vst1[i][j])
					map[i][j]='.';
				vst[i][j]=1;
			}
		}
	}
}

int main()
{
	int i,j;	
	int curdir;
	while(1)
	{
		memset(vst,0,sizeof(vst));
		memset(vst1,0,sizeof(vst1));
		for(i=0;i<8;i++)
		{
 			for(j=0;j<8;j++)
			{
				scanf("%c",&map[i][j]);
				map1[i][j]=map[i][j];
				if(i==0&&j==1&&map[0][0]=='-'&&map[0][1]=='-')
					return 0;
				if(map[i][j]=='<')
					sx=i,sy=j,curdir=2;
				else if(map[i][j]=='>')
					sx=i,sy=j,curdir=0;
				else if(map[i][j]=='^')
					sx=i,sy=j,curdir=1;
				else if(map[i][j]=='v')
					sx=i,sy=j,curdir=3;
			}
			getchar();
		}
		map1[sx][sy]=map[sx][sy]='.';
		while(1)
		{
			scanf("%s",&opr);
			if(strcmp(opr,"#")==0)
				break;
			else if(opr[0]=='t')
			{
				scanf("%s",&opr);
				if(opr[0]=='l')
				{
					curdir=(curdir+1)%4;
				}
				if(opr[0]=='r')
				{
					curdir=(curdir+4-1)%4;
				}
				if(opr[0]=='b')
				{
					curdir=(curdir+2)%4;
				}
			}
			else if(opr[0]=='m')
			{
				int step;
				scanf("%d",&step);
				if(step>8)
					step=8;
				fun_move(curdir,step);
			}
		}
		if(curdir==0)
			map[sx][sy]='>';
		else if(curdir==1)
			map[sx][sy]='^';
		else if(curdir==2)
			map[sx][sy]='<';
		else if(curdir==3)
			map[sx][sy]='v';
		for(i=0;i<8;i++)
		{
			for(j=0;j<8;j++)
				printf("%c",map[i][j]);
			printf("\n");
		}
		getchar();
	}
	return 0;
}



/*
.W...c..
.p..T..t
D..>..Pr
....aP.P
p.d.C...
.....p.R
.K......
Z...JQ..
move 5
turn right
move 0
turn back
move 10
turn left
move 10
turn left
move 20
#
--

*/

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