Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define mem(x,y) memset(x,y,sizeof(x))
  5. #define PI acos(-1.00)
  6. #define ERR 1e-9
  7. #define __ ios_base::sync_with_stdio(0); cin.tie(0);
  8. #define file freopen("input.txt", "rt", stdin);freopen("output.txt", "wt", stdout);
  9.  
  10. const int inf=0x7FFFFFFF ;
  11. typedef long long ll;
  12.  
  13. ll _GCD(ll a,ll b){return b?_GCD(b,a%b):a;}//gcd
  14.  
  15. //prototypes
  16. ll solution();
  17.  
  18. ll N;
  19. ll mark[105][105];
  20. ll xx[]={-2,-2,2,2,-1,-1,1,1};
  21. ll yy[]={1,-1,1,-1,2,-2,2,-2};
  22. void DFS(ll i,ll j,ll col)
  23. {
  24. if(i<1||i>N||j<1||j>N)
  25. return;
  26. if(mark[i][j]!=-1)
  27. return ;
  28. mark[i][j]=col;
  29. for(ll k=0;k<8;k++)
  30. {
  31. DFS(i+xx[k],j+yy[k],!col);
  32. }
  33.  
  34. }
  35.  
  36. int main()
  37. {
  38. //__;
  39. //file;
  40. int tc=1,cas=0;
  41. //cin>>tc;
  42. while(tc--)
  43. {
  44. //printf("Case %d: ",++cas);
  45. solution();
  46. }
  47. return 0;
  48. }
  49.  
  50. ll solution()
  51. {
  52. cin>>N;
  53. mem(mark,-1);
  54. ll col=1;
  55. for(ll i=1;i<=N;i++)
  56. {
  57. for(ll j=1;j<=N;j++)
  58. {
  59. if(mark[i][j]==-1){
  60. DFS(i,j,col);
  61. col=!col;
  62. }
  63. }
  64. }
  65. char s[]={'W','B'};
  66. for(ll i=1;i<=N;i++)
  67. {
  68. for(ll j=1;j<=N;j++)
  69. {
  70. cout<<s[mark[i][j]];
  71. }
  72. cout<<endl;
  73. }
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement