Advertisement
Guest User

Untitled

a guest
May 10th, 2016
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include <list>
  2. #include <map>
  3. #include <set>
  4. #include <deque>
  5. #include <stack>
  6. #include <queue>
  7. #include <algorithm>
  8. #include <sstream>
  9. #include <iostream>
  10. #include <iomanip>
  11. #include <cstdio>
  12. #include <cmath>
  13. #include <cstdlib>
  14. #include <memory.h>
  15. #include <ctime>
  16. #include <bitset>
  17.  
  18. using namespace std;
  19.  
  20. #define ABS(a) ((a>0)?a:-(a))
  21. #define MIN(a,b) ((a<b)?(a):(b))
  22. #define MAX(a,b) ((a<b)?(b):(a))
  23. #define FOR(i,a,n) for (int i=(a);i<(n);++i)
  24. #define MEMS(a,b) memset((a),(b),sizeof(a))
  25. #define FI(i,n) for (int i=0; i<(n); ++i)
  26. #define pnt pair <int, int>
  27. #define mp make_pair
  28. #define LL long long
  29. #define U unsigned
  30.  
  31. int dp[10][10][10][10][2];
  32.  
  33. int dx1[]={2,2,1,1,-2,-2,-1,-1};
  34. int dy1[]={1,-1,2,-2,1,-1,2,-2};
  35. int dx2[]={-1,-1};
  36. int dy2[]={1,-1};
  37.  
  38. bool isValid(int x, int y) {
  39.     return ((x>=0) && (x<8) && (y>=0) && (y<8));
  40. }
  41.  
  42. int r(int x1, int y1, int x2, int y2, int f) {
  43.     if (dp[x1][y1][x2][y2][f] != -1)
  44.         return dp[x1][y1][x2][y2][f];
  45.     if (f == 0) {
  46.         FOR(k,0,8) {
  47.             int nx = x1+dx1[k];
  48.             int ny = y1+dy1[k];
  49.             if (!isValid(nx,ny))
  50.                 continue;
  51.             if ((nx == x2) && (ny == y2))
  52.                 return dp[x1][y1][x2][y2][f] = 0;
  53.             if (r(nx,ny,x2,y2,1) == 0) {
  54.                 return dp[x1][y1][x2][y2][f] = 0;
  55.             }
  56.         }
  57.         return dp[x1][y1][x2][y2][f] = 1;
  58.     }
  59.     else {
  60.         FOR(k,0,2) {
  61.             int nx = x2 + dx2[k];
  62.             int ny = y2 + dy2[k];
  63.             if (!isValid(nx,ny))
  64.                 continue;
  65.             if ((nx == x1) && (ny == y1)) {
  66.                 if ((x1 == 0) || (x1 == 7) || (y1 == 0) || (y1 == 7))
  67.                     continue;
  68.                 return dp[x1][y1][x2][y2][f] = 1;
  69.             }
  70.             if (nx == 0)
  71.                 return dp[x1][y1][x2][y2][f] = 1;
  72.             if (r(x1,y1,nx,ny,0) == 1) {
  73.                 return dp[x1][y1][x2][y2][f] = 1;
  74.             }
  75.         }
  76.         return dp[x1][y1][x2][y2][f] = 0;
  77.     }
  78. }
  79.  
  80. string s1,s2,s3;
  81.  
  82. int main()
  83. {
  84. #ifdef Fcdkbear
  85.         freopen("in.txt", "r", stdin);
  86.         //freopen("out.txt", "w", stdout);
  87.         double beg = clock();
  88. #endif
  89.  
  90.         MEMS(dp,-1);
  91.         cin>>s1>>s2>>s3;
  92.         int f = r(s2[1] - '1', s2[0] - 'a', s3[1] - '1', s3[0] - 'a', s1[0] == 'b');
  93.         if (f)
  94.             cout<<"Black"<<endl;
  95.         else
  96.             cout<<"White"<<endl;
  97.  
  98. #ifdef Fcdkbear
  99.         double end = clock();
  100.         fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
  101. #endif
  102.         return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement