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

新手~实在是找不出为啥A不了!求助!

Posted by Ga091an at 2017-03-04 10:48:23 on Problem 1979
#include<iostream>
using namespace std;

int count;
int w,h;
char tiles[25][25];
int dir[2][4]={0,1,0,-1,1,0,-1,0};
int nx,ny;

void dfs(int x,int y){
	count++;
	tiles[x][y]='#';
	for(int i=0;i<4;i++){
	nx=x+dir[0][i],ny=y+dir[1][i];
	if(0<=nx&&nx<w&&0<=ny&&ny<h&&tiles[nx][ny]=='.') dfs(nx,ny);
	}
	return;
}

void solve(){
	int m,n;
	for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(tiles[i][j]=='@') {m=i,n=j;}
			}
	}
	dfs(m,n);
	cout<<count;
}

int main() {
	while(cin>>w>>h,w&&h){
		count=0;
			for(int i=0;i<h;i++){
			for(int j=0;j<w;j++)
				{cin>>tiles[i][j];}
		}
	solve();
	}
	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