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

为什么我这题2386能过,1562不能过啊,一样的代码啊!

Posted by chenzeyu at 2010-01-21 13:30:14 on Problem 1562
#include<iostream>
#include<fstream>
using namespace std;

const int MAXN = 110;
char map[MAXN][MAXN];
int vis[MAXN][MAXN];

void dfs(int x,int y)
{
	if(vis[x][y] == 1 || map[x][y] == '*'|| map[x][y] == 0)	return;
	vis[x][y] = 1;
	dfs(x-1,y-1);dfs(x-1,y);dfs(x-1,y+1);
	dfs(x,y-1);				dfs(x,y+1);
	dfs(x+1,y-1);dfs(x+1,y);dfs(x+1,y+1);
}
int main()
{

	int n,m,cnt;
	while(cin >> n >> m)
	{
		memset(map,0,sizeof(map));
		memset(vis,0,sizeof(map));
		cnt = 0;
		if(n == 0)break;

		for(int i = 1;i <= n;++i)
			for(int j = 1;j <= m;++j)
				cin >> map[i][j];

		for(int x = 1; x <= n;++x)
			for(int y = 1;y <= m;++y)
				if(vis[x][y] == 0 && map[x][y] == '@')
				{
					++cnt;
					dfs(x,y);
				}
		cout << cnt << 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