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

太恶心了 1562就过了 为什么这个过不了??????????????大牛看看啊 wa哭了

Posted by shaohua2208 at 2009-04-11 16:42:04 on Problem 2386
#include<iostream>
using namespace std;
int sum = 0;
int num[10000][10000] = {0};
char teststr[10000][10000];
void search(int x,int y){
	num[x][y] = 0;
	if(num[x + 1][y] == 1){
		search(x + 1,y);
	}
	if(num[x][y + 1] == 1){
		search(x,y + 1);
	}
	if(num[x - 1][y] == 1){
		search(x - 1,y);
	}
	if(num[x][y - 1] == 1){
		search(x,y - 1);
	}
	if(num[x + 1][y - 1] == 1){
		search(x + 1,y - 1);
	}
	if(num[x + 1][y + 1] == 1){
		search(x + 1,y);
	}
	if(num[x - 1][y - 1] == 1){
		search(x - 1,y - 1);
	}
	if(num[x - 1][y + 1] == 1){
		search(x - 1,y + 1);
	}
	return;
}
int main()
{
	int i,j;
	int x,y;
	memset(num,0,2 * sizeof(int));
//	freopen("2386.txt","r",stdin);
	cin>>x>>y;
	for(i = 0; i < x; i++){
		cin>>teststr[i];
	}
	for(i = 0; i < x; i++){
		for(j = 0; j < y; j++){
			if(teststr[i][j] == 'W'){
				num[i + 1][j + 1] = 1;
			}
			else{
				num[i + 1][j + 1] = 0;
			}
		}
	}
	for(i = 1; i <= x; i++){
		for(j = 1; j <= y; j++){
			if(num[i][j] == 1){
				sum++;
				search(i,j);
			}
		}
	}
	cout<<sum<<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