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 986677841 at 2016-07-29 21:49:59 on Problem 1979
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;
int n,m;
struct node
{
	int x,y;
}u,v;
bool used[1001][1001];
queue<node>Q;
char map[1001][1001];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main()
{
	while(~scanf("%d%d",&m,&n)&&m&&n)
		{
			memset(used,0,sizeof(used));
			for(int i=1;i<=n;i++)
				{
					scanf("%s",map[i]+1);
					for(int j=1;j<=m;j++)
						if(map[i][j]=='@')
							u.x=i,u.y=j;			
				}
			Q.push(u);
			used[u.x][u.y]=1;
			int ans=0;
			while(!Q.empty())
				{
					u=Q.front();
					ans++;
					Q.pop();
					for(int i=0;i<4;i++)
						{
							int xx=u.x+dx[i],yy=u.y+dy[i];
							if(xx<=0||yy<=0||xx>n||yy>m)
								continue;
							if(map[xx][yy]=='#'||used[xx][yy])continue;
							v.x=xx,v.y=yy;
							used[xx][yy]=1;
							Q.push(v);
						}
				}
			printf("%d\n",ans);
		}
}

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