poj-1979 DFS

Source: Internet
Author: User

1#include"CString"2#include"Cstdio"3 Const intmaxn= -+5;4 CharTILE[MAXN][MAXN];//Block Lattice5 intM,N,IDX[MAXN][MAXN];//m row n column, IDX determines if it has visited6 inta[]={-1,0,1,0};7 intb[]={0,-1,0,1};//Moving8 intNum//number of black squares9 voidDfsintRintc) {Ten     if(r<0|| r>=m| | c<0|| C>=n)return;//Out of bounds One     if(idx[r][c]>0|| tile[r][c]=='#')return;//already visited lattice or red lattice AIdx[r][c]=++num;//If tile has not been accessed, tag access, num+1 -      for(intI=0;i<4; i++){ -DFS (r+a[i],c+b[i]); the     } - } - intMain () { -      while(SCANF ("%d%d", &n,&m) = =2&&n&&L) { +          for(intI=0; i<m;i++) -scanf"%s", Tile[i]); +memset (IDX,0,sizeof(IDX)); Anum=0; at          for(intI=0; i<m;i++) -              for(intj=0; j<n;j++) -                 if(tile[i][j]=='@'){ -                      - DFS (I,J); -                      Break; in                 } -printf"%d\n", num); to     } +     return 0; - } the  

poj-1979 DFS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.