Advertisement
Guest User

TaskB

a guest
Nov 10th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1. #define TASKNAME "chess"
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <cmath>
  6. #include <algorithm>
  7. #include <ctime>
  8. #include <cctype>
  9. #include <cstdlib>
  10. #include <cassert>
  11. #include <functional>
  12. #include <iomanip>
  13. #include <string>
  14. #include <cstring>
  15. #include <map>
  16. #include <set>
  17. #include <vector>
  18.  
  19. #define EPS (1e-9)
  20. #define INF (int(1e9))
  21. #define INFLONG ((long long)(1e18))
  22. #define sqr(a) ((a) * (a))
  23. #define all(a) (a).begin(), (a).end()
  24. #define zero(a) memset(a, 0, sizeof(a))
  25. #define abs(a) (((a) < 0) ? -(a) : (a))
  26. #define sz(a) (int)a.size()
  27. #define fst first
  28. #define snd second
  29. #define y1 osrughosduvgarligybakrybrogvba
  30. #define y0 aosfigdalrowgyalsouvgrlvygalri                              
  31. #define mp make_pair
  32. #define pb push_back
  33. #define next dlkjdslfkdj
  34. #define prev dsdflksdfjl
  35. #define hash lkdfjldskfj
  36. #define pi 3.1415926535897932384626433832795
  37. #define eprintf(...) fprintf(stderr, __VA_ARGS__)
  38.  
  39. using namespace std;
  40.  
  41. typedef long long ll;
  42. typedef long double ld;
  43. typedef vector <int> vi;
  44. typedef vector <vi> vvi;
  45. typedef vector <bool> vb;
  46. typedef vector <ll> vll;
  47. typedef pair <int, int> pii;
  48. typedef pair <ll, ll> pll;
  49. typedef pair <ll, int> pli;
  50. typedef pair <int, ll> pil;
  51. typedef vector <pii> vpii;
  52.  
  53. const int maxn = 1010;
  54.  
  55. int n, m;
  56. int x[2][3];
  57. int y[2][3];
  58. int color[maxn][maxn];        
  59. int dx[3][8] = {{1, 1, -1, -1, 1, -1, 0, 0}, {1, -1, 0, 0, 0, 0, 0, 0}, {1, 1, -1, -1, 0, 0, 0, 0}};
  60. int dy[3][8] = {{1, -1, 1, -1, 0, 0, 1, -1}, {0, 0, 1, -1, 0, 0, 0, 0}, {1, -1, 1, -1, 0, 0, 0, 0}};
  61. int sz[3] = {8, 4, 4};
  62.  
  63. inline bool check_inside(int x, int y)
  64. {
  65.   return x >= 1 && x <= n && y >= 1 && y <= m;
  66. }
  67.  
  68. inline bool is_check(int type, int x0, int y0, int x1, int y1)
  69. {
  70.   assert(type >= 0 && type <= 2);
  71.   if (!type)
  72.     return abs(x0 - x1) <= 1 && abs(y0 - y1) <= 1;
  73.   if (type == 1)
  74.     return !((x0 - x1) * (y0 - y1));
  75.   return abs(x0 - x1) == abs(y0 - y1);
  76. }
  77.  
  78. inline bool is_check()
  79. {
  80.   int X = x[0][0];
  81.   int Y = y[0][0];
  82.   return (color[x[1][0]][y[1][0]] == 2 && is_check(0, x[1][0], y[1][0], X, Y)) ||
  83.          (color[x[1][1]][y[1][1]] == 2 && is_check(1, x[1][1], y[1][1], X, Y)) ||
  84.          (color[x[1][2]][y[1][2]] == 2 && is_check(2, x[1][2], y[1][2], X, Y));
  85. }
  86.  
  87. int main()
  88. {
  89.   freopen(TASKNAME".in", "r", stdin);
  90.   freopen(TASKNAME".out", "w", stdout);
  91.   scanf("%d%d", &n, &m);
  92.   for (int i = 0; i < 2; i++)
  93.     for (int j = 0; j < 3; j++)
  94.       scanf("%d%d", &x[i][j], &y[i][j]), color[x[i][j]][y[i][j]] = i + 1;
  95.   for (int type = 0; type < 3; type++)
  96.     for (int it = 0; it < sz[type]; it++)
  97.     {
  98.       int lx = x[0][type], ly = y[0][type];
  99.       int nx = lx + dx[type][it], ny = ly + dy[type][it];
  100.       if (!check_inside(nx, ny) || color[nx][ny] == 1)
  101.         continue;
  102.       x[0][type] = nx;
  103.       y[0][type] = ny;
  104.       int lcr = color[nx][ny];
  105.       color[nx][ny] = 1;
  106.       color[lx][ly] = 0;
  107.       if (!is_check())
  108.       {
  109.         printf("%d %d %d %d\n", lx, ly, nx, ny);
  110.         printf("%d %d %d %d\n", nx, ny, lx, ly);
  111.         return 0;
  112.       }
  113.       x[0][type] = lx;
  114.       y[0][type] = ly;
  115.       color[nx][ny] = lcr;
  116.       color[lx][ly] = 1;
  117.     }    
  118.   printf("-1\n");
  119.   return 0;                                  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement