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
北京大学《ACM-ICPC竞赛训练》暑期课面向全球招生。容量有限,报名从速!

输出重定向未注释,贡献四个WA

Posted by Matthew_lyns at 2017-04-21 17:22:21 on Problem 1979
#include <iostream>

#define M  20 + 10
#define N  20 + 10
using namespace std;

int m, n;
int count;
char map[M][N];
int dir[4][2] = {{-1, 0},{1, 0},{0, 1},{0, -1}};

void dfs(int x, int y)
{
	int newx, newy;
	
	map[x][y] = '#';
	for(int i = 0; i < 4; i++)
	{
		newx = x + dir[i][0];
		newy = y + dir[i][1];
		if(newx >= 0 && newx < n && newy >= 0 && newy < m && map[newx][newy] == '.')
		{
			count ++;
			dfs(newx, newy);
		}
	}
}

int main()
{
	int x = 0, y = 0;
	int result = 0;
	//freopen("input.txt","r",stdin);

	while(scanf("%d%d", &m, &n) != EOF && m && n)
	{
		memset(map, 0, sizeof(map));
		count = 1;
		
		for(int i = 0; i < n; i++)
		{
			scanf("%s", &map[i]);
		}
		
		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < m; j++)
			{
				if(map[i][j]== '@'){
					x = i;
					y = j;
					map[x][y] = '.';
				}
			}
		}
		dfs(x, y);
		result = count;
		cout <<result<<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