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 ldc_hust at 2008-04-25 14:33:09 on Problem 1979
#include<iostream>
using namespace std;
int W,H;
char ch[22][22];
int tag[21][21];
int count=0;
void TraceBack(int x,int y)
{
    if(y-1>0 && tag[y-1][x]==0)
	{
		tag[y-1][x]=1;
        count++;
		TraceBack(x,y-1);
	}
	if(x+1<=W && tag[y][x+1]==0)
	{
		tag[y][x+1]=1;
		count++;
		TraceBack(x+1,y);
	}
	if(y+1<=H && tag[y+1][x]==0)
	{
		tag[y+1][x]=1;
		count++;
		TraceBack(x,y+1);
	}
	if(x-1>0 && tag[y][x-1]==0)
	{
		tag[y][x-1]=1;
		count++;
		TraceBack(x-1,y);
	}
}
int main()
{
	while(cin>>W>>H  && W)
	{
		count=0;
		int i,j;
		int x,y;
		for(i=1;i<=H;i++)
			for(j=1;j<=W;j++)
			{
				cin>>ch[i][j];
				if(ch[i][j]=='.')
					tag[i][j]=0;
				else
					if(ch[i][j]=='#')
						tag[i][j]=1;
				if(ch[i][j]=='@')
				{
					tag[i][j]=0;
					x=j;
					y=i;
				}
			}
		TraceBack(x,y);
		cout<<count<<endl;
	}
	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