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

Re:如果不看discuss 绝对不知道 数据范围100绝对是个坑 1000真的能过

Posted by LSLIAOWEI at 2016-07-20 16:52:21 on Problem 2386
In Reply To:如果不看discuss 绝对不知道 数据范围100绝对是个坑 1000真的能过 Posted by:LSLIAOWEI at 2016-07-20 16:21:50
#include <stdio.h>
#define N 1000	//据说数据这里有个坑 开成1000就过了 如果过了就真的有个坑
char arr[N][N];
int r, l, ans;

void dfs(int x, int y)
{
	int i, j;
	int dx, dy;
	int nx, ny;
	arr[x][y] = '.';

	for(dx=-1; dx<=1; dx++)
		for(dy=-1; dy<=1; dy++)
		{
			nx = x + dx;
			ny = y + dy;
			if(arr[nx][ny] == 'W' && nx>=0 && nx<r && ny>=0 && ny<l)
				dfs(nx, ny);
		}
	return ;
}

int main()
{
	int i, j, k;
	scanf("%d %d", &r, &l);
	for(i=0; i<r; i++)
		//for(j=0; j<l; j++)	//我只想问为何用%c 样例输出就是8
		//	scanf("%c", &arr[i][j]);  //用%s 样例输出就是3
		//	菊苣解答:scanf() 中;%c会将换行符\n识别成一个字符存到下一个数组位置,而不会识别为字符结束标志
		//	也可以用fflush(stdin);//去掉输入缓冲区的内容,(去掉回车)
			scanf("%s", arr[i]);

	for(i=0; i<r; i++)
		for(j=0; j<l; j++)
			if(arr[i][j] == 'W')
			{
				dfs(i, j);
				ans++;
			}
	printf("%d\n", ans);

	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