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

完全一样的算法,我的怎么是wa?

Posted by tide713 at 2005-04-22 22:23:46 on Problem 2386
In Reply To:帮帮忙 看看哪里错了 Posted by:ync at 2005-04-01 19:07:55
> #include<stdio.h>
> #include<string.h>
> char A[105][105];
> int N,M;
> void recur(int i,int j)
> {
> 	A[i][j]='W';
> 	if(i>1&&A[i-1][j]=='.') recur(i-1,j);
> 
> 	if(i>1&&j>1&&A[i-1][j-1]=='.') recur(i-1,j-1);
> 
> 	if(j>1&&A[i][j-1]=='.') recur(i,j-1);
> 
> 	if(i<N&&j>1&&A[i+1][j-1]=='.') recur(i+1,j-1);
> 
> 	if(i<N&&A[i+1][j]=='.') recur(i+1,j);
> 
> 	if(i<N&&j<M&&A[i+1][j+1]=='.') recur(i+1,j+1);
> 
> 	if(j<M&&A[i][j+1]=='.') recur(i,j+1);
> 
> 	if(i>1&&j<M&&A[i-1][j+1]=='.') recur(i-1,j+1);
> 	return ;
> 
> }
> int main()
> {
> 	int i,j,block;
> 	while(1)
> 	{
> 		scanf("%d%d",&N,&M); 
> 		for(i=1;i<=N;i++)
> 		{	 
> 			scanf("%s",A[i]+1); 
> 		}
> 	
> 		block=0;
> 		for(i=1;i<=N;i++)
> 		{
> 			for(j=1;j<=M;j++)
> 			{
> 				if(A[i][j]=='W')  continue;
> 				block++;
> 				recur(i,j); 
> 			}
> 		}
> 	
> 		printf("%d\n",block);   break;
> 	}//while
> 	return 0;
> }
> /*  N x M (1 <= N <= 100; 1 <= M <= 100
下面是我的程序,过不了,不知道为什么。
#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>
char aaa[102][102];
int n1,m1;//要输入的变量,表示行和列
int b[8][2]={{0,1},{0,-1},{1,0},{-1,0},{1,1},{-1,-1},{1,-1},{-1,1}};//在递归的时候向八个方向扫描时用
int xunhuan(int i,int j)
{   int k;
    
		  aaa[i][j]='.';
                   
				  //if(a////////////////////////////////////////////
			      for( k=0;k<8;k++)
				  {    int b1=b[k][0];
				       int b2=b[k][1];
					   i=i+b1;
					   j=j+b2;
                        
					    if(i>=0&&i<n1&&j>=0&&j<m1&&aaa[i][j]=='W')
						  xunhuan(i,j);
						else
						{i=i-b1;j=j-b2;}
				

				  }

	return 1;
}
void main()
{    int i,j;
     
     //int n,m;
	 cin>>n1>>m1;
	 for(i=0;i<n1;i++)
	 cin>>aaa[i];     //输入数组
	 int bbb=0;
	 for(i=0;i<n1;i++)
		 for(j=0;j<m1;j++)
		 {   
			 if(aaa[i][j]=='W')
			 {   bbb++;
				 xunhuan(i,j);      //调用函数扫描
			 }
		 }
		 cout<<bbb<<endl;

}

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