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

第一次写 写的好恶心,有时间要给给代码,实在太菜了,附代码,竟然是大写的X,wa了好几次

Posted by zhao20111438 at 2013-08-08 22:59:50 on Problem 1111
#include<iostream>
using namespace std;
char arm[50][50];
int visited[50][50];
int Count;
int n,m;
void bfs(int lom,int rom)
{

	if(lom>n||lom<=0||rom<=0||rom>m||arm[lom][rom]=='.')
	{
		Count++;
		return;	
	}
	if(arm[lom+1][rom]=='X')
	{	
		if(!visited[lom+1][rom])
		{
			visited[lom+1][rom]=1;
			bfs(lom+1,rom);
		}
	}
	else
		Count++;
	if(arm[lom-1][rom]=='X')
	{	
		
		if(!visited[lom-1][rom])
		{
			visited[lom-1][rom]=1;
			bfs(lom-1,rom);
		}
		
	}
	else
		Count++;
	if(arm[lom][rom-1]=='X')
	{
		if(!visited[lom][rom-1])
		{
			visited[lom][rom-1]=1;
			bfs(lom,rom-1);
		}
	}
	else
			Count++;
	if(arm[lom][rom+1]=='X')
	{
		if(!visited[lom][rom+1])
		{
			visited[lom][rom+1]=1;
			bfs(lom,rom+1);
		}
		
	}
	else
			Count++;
	if(arm[lom-1][rom-1]=='X')
	{
		if(lom!=1&&rom!=1&&!visited[lom-1][rom-1])
		{
			visited[lom-1][rom-1]=1;
			bfs(lom-1,rom-1);
		}
	}
	if(arm[lom-1][rom+1]=='X')
	{
		if(lom!=1&&rom!=m&&!visited[lom-1][rom+1])
		{
			visited[lom-1][rom+1]=1;
			bfs(lom-1,rom+1);
		}
	}
	if(arm[lom+1][rom+1]=='X')
	{
		if(lom!=n&&rom!=m&&!visited[lom+1][rom+1])
		{
			visited[lom+1][rom+1]=1;
			bfs(lom+1,rom+1);
		}	
	}
	if(arm[lom+1][rom-1]=='X')
	{
		if(lom!=n&&rom!=1&&!visited[lom+1][rom-1])
		{
			visited[lom+1][rom-1]=1;
			bfs(lom+1,rom-1);
		}
	}
	return;
}

int main()
{
	int x,y;
	while(1)
	{
		Count=0;
		cin>>n>>m>>x>>y;
		if(!n&&!m&&!x&&!y)
			{
				return 0;	
			}
		
		memset(visited,0,sizeof(visited));
		memset(arm,0,sizeof(arm));
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
			cin>>arm[i][j];
		visited[x][y]=1;
		if(arm[x][y]=='.')
			Count=0;
		else
		{
			bfs(x,y);
		}
		
		cout<<Count<<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