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

why WA?

Posted by lbcharry at 2005-09-11 16:30:57 on Problem 2386

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

int main()
{
	int i,j;
	int N,M;
	int Number;       
	int adjacent[8][2];
	char gragh[101][101];
	int  map[101][101];

	//初始化;
	adjacent[0][0]= 1;  adjacent[0][1]= 0;
	adjacent[1][0]= 1;  adjacent[1][1]=-1;
	adjacent[2][0]= 1;  adjacent[2][1]= 1;
	adjacent[3][0]=-1;  adjacent[3][1]= 0;
	adjacent[4][0]= 0;  adjacent[4][1]=-1;
	adjacent[5][0]= 0;  adjacent[5][1]= 1;
	adjacent[6][0]=-1;  adjacent[6][1]= 1;
	adjacent[7][0]=-1;  adjacent[7][1]=-1;

    cin>>N>>M;

	for(i=0;i<N;i++)
	{
		for(j=0;j<M;j++)
		{
			cin>>gragh[i][j];
			if(gragh[i][j]=='W')
			{
				map[i][j]=-2;
			}
			else
			{
				map[i][j]=-1;
			}
		}
	}

         Number=0;
	for(i=0;i<N;i++)
	{
		for(j=0;j<M;j++)
		{
			if(gragh[i][j]=='.')continue;
			int x;
		         int y;
			bool flag=true;
			for(int k=0;k<8;k++)
			{
				x=i+adjacent[k][0];
				y=j+adjacent[k][1];
				if(x>=0&&x<N&&y>=0&&y<M&&map[x][y]>=0)
				{
					map[i][j]=map[x][y];
					flag=false;
					break;
				}
			}
			if(flag)
			{
				map[i][j]=Number++;
			}
		}
	}
	cout<<Number<<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