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

通俗易懂 GCC 0s

Posted by 842923744 at 2018-04-17 21:31:36 on Problem 1979 and last updated at 2018-04-17 22:28:11
#include<stdio.h>
#include<stdlib.h>
char room[20][20];
int dfs(char room[][20],int h,int w,int i,int j){
    if(i<0||i>=h||j<0||j>=w||room[i][j]=='#')
        return 0;
    int n=1;
    room[i][j]='#';
    n+=(dfs(room,h,w,i+1,j)+dfs(room,h,w,i-1,j)+dfs(room,h,w,i,j+1)
        +dfs(room,h,w,i,j-1));
    return n;
}
int main(){
    int w,h;
    while(scanf("%d%d",&w,&h)!=EOF){
        if(w==0||h==0)
            break;
        int sum,i,j,t1,t2;
        for(i=0;i<h;i++){
            scanf("%s",&room[i]);
        }
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if(room[i][j]=='@'){
                t1=i;t2=j;
                }
            }
        }
        sum=dfs(room,h,w,t1,t2);
        printf("%d\n",sum);
    }
    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