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

贴贴挫代码

Posted by TSERROF at 2012-10-07 11:26:51 on Problem 1979
#include<iostream>
#include <cstring>
using namespace std;
char map[105][105];
int ss[105][105];
int DFS(int i,int j)
{
	if(map[i][j]=='#')return 0;
	map[i][j]='#';
	ss[i][j]=DFS(i+1,j)+DFS(i-1,j)+DFS(i,j+1)+DFS(i,j-1)+1;
	return ss[i][j];
}
int main()
{
	int row,col;
	while(cin>>col>>row && col && row)
	{
		memset(map,'#',sizeof(map));
		memset(ss,0,sizeof(ss));
		int si,sj;
		for(int i=1;i<=row;++i)
		{
			for(int j=1;j<=col;++j)
			{
				cin>>map[i][j];
				if(map[i][j]=='@')si=i,sj=j;
			}
		}
		cout<<DFS(si,sj)<<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