UVA 260-il Gioco dell ' X

Source: Internet
Author: User

Exercises

There must be someone to win, not black or white; the winning condition is: Black is from the top to the next, white is from left to right;

1#include <cstdio>2 using namespacestd;3 intN;4 Charboard[201][201];5 Const intdirection[][2] = {{-1,-1},{-1,0},{0,-1},{0,1},{1,0},{1,1}};6 voidDFS (intIintJCharCint&win)7 {8BOARD[I][J] ='.';9     if(c = ='b'&& i = = N1) win =1;Ten     if(c = ='W'&& J = = N1) win =2; One      for(intx=0; x<6; ++x) { A         intI_next = i+direction[x][0]; -         intJ_next = j+direction[x][1]; -         if(i_next<0|| I_next>=n | | j_next<0|| J_next>=n)Continue; the         if(Board[i_next][j_next] = =c) - DFS (I_next, J_next, C, win); -     } - } + intMain () - { +     //reopen ("Input.txt", "RT", stdin); A     intCase =1; at      while(SCANF ("%d",&N)) { -         if(! N Break; -          for(intI=0; i<n; ++i) -scanf"%s", Board[i]); -         intWin =0;//Win=1:black Win=2:white -          for(intI=0; i<n; ++i) in             if(board[i][0] =='W') -DFS (I,0,'W', win); to          for(intj=0; j<n; ++j) +             if(board[0][J] = ='b') -DFS (0J'b', win); the         if(Win = =1) printf ("%d b\n", case++); *         Elseprintf"%d w\n", case++); $     }Panax Notoginseng     return 0; -}

Exercises

There must be a victory, so it is enough only to judge Black's victory. Black wins on the condition that he can walk from the first to the last line, White's victory condition is to be able to go out the first column to the last column;

1#include <iostream>2 using namespacestd;3 4 Const intMAXN = $+Ten;5 6 CharBOARD[MAXN][MAXN];7 8 voidWbintXintYintNCharCO)9 {Ten     if(x>=0&& x<n && y>=0&& y<N) One         if(Board[x][y] = =CO) A         { -Board[x][y] ='1'; -WB (x1, Y1, N, CO); theWB (x, Y1, N, CO); -WB (x+1, Y, N, CO); -WB (x1, Y, N, CO); -WB (x, y+1, N, CO); +WB (x+1, y+1, N, CO); -         } + } A  at intMain () - { -     intN, I, j, ans =0; -      while(Cin>>n &&N) -     { -          for(i =0; I < n; i++) in              for(j =0; J < N; J + +) -CIN >>Board[i][j]; to  +         BOOLFlag =false; -         //Black:first Row the          for(j =0; J < N; J + +) *             if(board[0][J] = ='b') $Wb0, J, N,'b');Panax Notoginseng          for(j =0; J < N; J + +) -             if(board[n-1][J] = ='1') the             { +cout << ++ans <<"B"<<Endl; AFlag =true; the                  Break; +             } -  $         if(flag) $             Continue; -         Elsecout << ++ans <<"W"<<Endl; -     } the     return 0; -}

UVA 260-il Gioco dell ' X

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.