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

我是这样读的(in)

Posted by cock at 2006-10-19 20:15:30
In Reply To:有空格没空行 Posted by:ecjtunh at 2006-10-19 20:13:53
#include<stdio.h>
#include<string.h>
const int M=20;
int a[M][M],finish;
struct Point
{
	int x,y;
}dir[8]={{0,1},{0,-1},{1,0},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
bool flag[M][M];
int n,m;
void DFS(int x,int y,int color)
{
	if (finish) return;	
	int t;
	Point nnd;
	for(t=0;t<8;t++)
	{
		nnd.x=x+dir[t].x;
		nnd.y=y+dir[t].y;
		if (nnd.x==n && nnd.y==m+1) {finish=1;break;}

		if (nnd.x<1 || nnd.x>n || nnd.y<1 || nnd.y>m || !flag[nnd.x][nnd.y] || (a[nnd.x][nnd.y]!=(color+1)%4)) continue;
		flag[nnd.x][nnd.y]=false;
		DFS(nnd.x,nnd.y,(color+1)%4);
		flag[nnd.x][nnd.y]=true;
	}
}
int main()
{
	int i,j,tst;
	char st[M];
	tst=0;
	while(scanf("%d%d",&n,&m)==2)
	{
		for(i=1;i<=n;i++)
			for(j=1;j<=m;j++)
			{
				scanf("%s",st);	
				a[i][j]=st[0]-'A';
			}
			
		finish=0;
		memset(flag,1,sizeof(flag));
		DFS(1,0,-1);
		printf("Case %d:\n",++tst);
		if (finish) printf("Yes!\n");
		else printf("No!\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