Codeforces-445a-dzy Loves Chessboard Problem Solving report

Source: Internet
Author: User

For the first time I feel that I should use DFS to solve this problem, but because I am not too familiar with DFS, so I gave up the idea;

But also want to follow this requirement to achieve the problem must be black and white, and then the character is ' B ' or ' W ' instead of '-', can be;

Let's stick to my code.

1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineN 100+105 using namespacestd;6 7 CharMaze[n][n];8 CharStr[n][n];9 intn,m;Ten  One intMainvoid) A { -      while(~SCANF ("%d%d",&n,&m)) -     { thememset (str,0,sizeof(str)); -            for(intI=0; i<n;++i) -scanf"%s", Maze[i]); -            for(intI=0; i<n;++i) +               for(intj=0; j<m;++j) { -                  if(maze[i][j]=='-') +STR[I][J] ='-'; A                  Else{ at                       if((i+j)%2==1) str[i][j]='B'; -                       Elsestr[i][j]='W'; -                  } -              } -            for(intI=0; i<n;++i) { -               for(intj=0; j<m;++j) inprintf"%c", Str[i][j]); -printf"\ n"); to           } +     } -      the     return 0; *}

I will then insert the code I copied from the other great god blogs about the DFS solution:

1#include <cstdio>2#include <iostream>3#include <algorithm>4 using namespacestd;5 6 intn,m;7 Charmap[ the][ the];8 intdir[][2]={{0,1},{0,-1},{-1,0},{1,0}};9 voidDFS (intXintYintnum)Ten { One     if(num==0) A     { -map[x][y]='W'; -     } the     Else -     { -map[x][y]='B'; -     } +     intFx,fy; -      for(intI=0;i<4; i++) +     { Afx=x+dir[i][0]; atfy=y+dir[i][1]; -         if(fx>=0&&fx<n&&fy>=0&&fy<m&&map[fx][fy]=='.') -         { -            if(num==0) -            { -DFS (Fx,fy,1); in            } -            Else to            { +DFS (Fx,fy,0); -            } the         } *     } $ }Panax Notoginseng intMain () - { thescanf"%d%d",&n,&m); +      for(intI=0; i<n;i++) A     { thescanf"%s", Map[i]); +     } -      for(intI=0; i<n;i++) $     { $          for(intj=0; j<m;j++) -         { -             if(map[i][j]=='.') the             { -DFS (I,j,0);Wuyi             } the         } -     } Wu      for(intI=0; i<n;i++) -     { Aboutprintf"%s\n", Map[i]); $     } -     return 0; -}

Codeforces-445a-dzy Loves Chessboard Problem Solving report

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.