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

RE G++.神牛帮我看看

Posted by alpc66 at 2010-09-15 22:26:17 on Problem 1573
#include<stdio.h>
#include<string.h>

const int WIDTH=20;
int row,col,entry;
int flag[WIDTH][WIDTH];
char grid[WIDTH][WIDTH];

int main()
{
	int i,j;
	while(scanf("%d%d%d",&row,&col,&entry))
	{
		if(!row&&!col&&!entry)
			break;
		memset(flag,0,sizeof(flag));
		for(i=0;i<row;i++)
			scanf(" %s",grid[i]);
		bool Dis=true;
		i=0;j=entry-1;
		flag[i][j]=1;
		int ni,nj;
		while(1)
		{
			if(i<0||j<0||i>=row||j>=col)break;
			ni=i;nj=j;
			if(grid[ni][nj]=='N')
			{
				i--;
				if(flag[i][j]){Dis=false;break;}
				if(i<row-1)
					flag[i][j]=flag[i+1][j]+1;
			}
			else if(grid[ni][nj]=='S')
			{
				i++;
				if(flag[i][j]){Dis=false;break;}
				if(i>0)
					flag[i][j]=flag[i-1][j]+1;
			}
			else if(grid[ni][nj]=='W')
			{
				j--;
				if(flag[i][j]){Dis=false;break;}
				if(j<col-1)
					flag[i][j]=flag[i][j+1]+1;
			}
			else if(grid[ni][nj]=='E')
			{
				j++;
				if(flag[i][j]){Dis=false;break;}
				if(j>0)
					flag[i][j]=flag[i][j-1]+1;
			}
		}
		if(Dis)
	    	 printf("%d step(s) to exit\n",flag[ni][nj]);
		
		else 
		{
			printf("%d step(s) before a loop of %d step(s)\n",flag[i][j]-1,flag[ni][nj]-flag[i][j]+1);
		}
	}
	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