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 nintendo at 2013-09-12 16:52:58 on Problem 1979
#include<cstring>
#include<iostream>

using namespace std;
//char input[30][30];
int room[30][30];//1为黑,0为红或边界 
int canreach[30][30];//1为已经到达,0为没有到达 
int tiles=0;

void dfs(int x,int y)
{
	if (room[x+1][y]&&!canreach[x+1][y]){
		tiles++;
		//printf("Found %d %d!\n",x+1,y);
		canreach[x+1][y]=1;
		dfs(x+1,y);
	}
	if (room[x-1][y]&&!canreach[x-1][y]){
		tiles++;
		//printf("Found %d %d!\n",x-1,y);
		canreach[x-1][y]=1;
		dfs(x-1,y);
	}
	if (room[x][y+1]&&!canreach[x][y+1]){
		tiles++;
		//printf("Found %d %d!\n",x,y+1);
		canreach[x][y+1]=1;
		dfs(x,y+1);
	}
	if (room[x][y-1]&&!canreach[x][y-1]){
		tiles++;
		//printf("Found %d %d!\n",x,y-1);
		canreach[x][y-1]=1;
		dfs(x,y-1);
	}
}

main()
{
	int largex,largey;
	int cntx,cnty;
	int peoplex,peopley;
	char in;

	cin>>largex>>largey;
	while (largex&&largey){
		memset(room,0,sizeof(room));
		memset(canreach,0,sizeof(canreach));
		tiles=0;
		for (cnty=1;cnty<=largey;cnty++){
			for (cntx=1;cntx<=largex;cntx++){
				cin>>in;
				switch (in){
					case '@':peoplex=cntx;peopley=cnty;
					case '.':room[cntx][cnty]=1;break;
				}
			}
		}
		dfs(peoplex,peopley);
		cout<<tiles<<endl;
		cin>>largex>>largey;
	}
	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