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

为什么在ZJU能过,在PKU过不了??

Posted by bobobo at 2005-11-22 21:04:41 on Problem 1111
程序如下:

#include<stdio.h>

char image[20][20];
int note[20][20];
int res=0;
int row,column;

void expand(int x,int y);

int main(){
  
	int clickx,clicky;
	int i,j;

	while(1){
	    scanf("%d%d%d%d",&row,&column,&clickx,&clicky);
		if(row==0&&column==0&&clickx==0&&clicky==0) break;

        for(i=0;i<row;i++) scanf("%s",image[i]);
        
        for(i=0;i<row;i++)
			for(j=0;j<column;j++)
				note[i][j]=0;

		res=0;
		expand(clickx-1,clicky-1);

		printf("%d\n",res);
	}

	return 0;
}

void expand(int x,int y){
    
    if(image[x][y]=='.') return;   
 
	note[x][y]=1;
	
    if(image[x-1][y]=='.'||x-1<0) res+=1;
	else if(!note[x-1][y]) expand(x-1,y);
    
	if(image[x+1][y]=='.'||x+1>=row) res+=1;
	else if(!note[x+1][y]) expand(x+1,y);

    if(image[x][y-1]=='.'||y-1<0) res+=1;
	else if(!note[x][y-1]) expand(x,y-1);
	
    if(image[x][y+1]=='.'||y+1>=column) res+=1;
	else if(!note[x][y+1]) expand(x,y+1);

	if(x-1>=0&&y-1>=0)
        if(image[x-1][y-1]=='X'&&!note[x-1][y-1]) expand(x-1,y-1);

	if(x-1>=0&&y+1<column)
        if(image[x-1][y+1]=='X'&&!note[x-1][y+1]) expand(x-1,y+1);
	
	if(x+1<row&&y-1>=0)
		if(image[x+1][y-1]=='X'&&!note[x+1][y-1]) expand(x+1,y-1);
	
	if(x+1<row&&y+1<column)
        if(image[x+1][y+1]=='X'&&!note[x+1][y+1]) expand(x+1,y+1);
	
	return;
}

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