Advertisement
999ms

Untitled

Aug 24th, 2020
1,276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x) begin(x),end(x)
  3.  
  4. using namespace std;
  5. using ll = long long;
  6.  
  7. void InitIO(string s = "") {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(nullptr);
  10.     cout.tie(nullptr); 
  11.     if (s.size()) {
  12.         freopen((s + ".in").c_str(), "r", stdin);
  13.         freopen((s + ".out").c_str(), "w", stdout);
  14.     }
  15. }
  16.  
  17. int type[3][5];
  18.  
  19. enum {
  20.     GREEN,
  21.     RED,
  22.     BLUE,
  23.     YELLOW
  24. };
  25.  
  26. int pos(int lvl, double x, double y) {
  27.     double h = sqrt(3) / 2;
  28.     y -= h * lvl;
  29.     if (lvl & 1) {
  30.         y = h - y;
  31.     }
  32.    
  33.     // x < y * tan(30)
  34.     // x < y * tan(30) + (h - y) * tan(30) * 2
  35.     // x < y * tan(30) + (h - y) * tan(30) * 2 + y * tan(30) * 2
  36.     // x < y * tan(30) + (h - y) * tan(30) * 4 + y * tan(30) * 2
  37.     const double PI = acos(-1);
  38.     double tg = tan(PI / 6);
  39.    
  40.     if (x < y * tg) return 0;
  41.     if (x < y * tg + (h - y) * tg * 2) return 1;
  42.     if (x < y * tg + (h - y) * tg * 2 + y * tg * 2) return 2;
  43.     if (x < y * tg + (h - y) * tg * 4 + y * tg * 2) return 3;
  44.     return 4;
  45. }
  46.  
  47. int main() {
  48.     InitIO();
  49.     string a, b;
  50.     int a1, d1, a2, d2;
  51.     cin >> a >> a1 >> d1;
  52.     cin >> b >> a2 >> d2;
  53.     map<string, int> mp;
  54.     mp["CD"] = -1;
  55.     mp["DB"] = 0;
  56.     mp["BC"] = 1;
  57.    
  58.     int t1 = mp[a];
  59.     int t2 = mp[b];
  60.    
  61.    
  62.     double x1 = 0;
  63.     double x2 = 0;
  64.     const double PI = acos(-1);
  65.     double alpha1 = a1 / 60.0 * PI / 3 - PI / 6;
  66.     double alpha2 = a2 / 60.0 * PI / 3 - PI / 6;
  67.    
  68.     alpha1 += t1 * PI / 3;
  69.     alpha2 += t2 * PI / 3;
  70.    
  71.    
  72.     double yd1 = d1 * cos(alpha1);
  73.     double yd2 = d2 * cos(alpha2);
  74.  
  75.     double xd1 = x1 + d1 * sin(alpha1);
  76.     double xd2 = x2 + d2 * sin(alpha2);
  77.    
  78.     double t_x = 2;
  79.     while (xd1 < 0) xd1 += t_x;
  80.     while (xd2 < 0) xd2 += t_x;
  81.     while (xd1 >= t_x) xd1 -= t_x;
  82.     while (xd2 >= t_x) xd2 -= t_x;
  83.    
  84.     double t_y = 4 * sqrt(3) / 2;
  85.     while (yd1 >= t_y) yd1 -= t_y;
  86.     while (yd2 >= t_y) yd2 -= t_y;
  87.    
  88.    
  89.    
  90.     double h = sqrt(3) / 2;
  91.     int lvl1 = yd1 / h;
  92.     int lvl2 = yd2 / h;
  93.    
  94.     type[0][0] = GREEN;
  95.     type[0][1] = RED;
  96.     type[0][2] = BLUE;
  97.     type[0][3] = YELLOW;
  98.     type[0][4] = GREEN;
  99.    
  100.     type[1][0] = BLUE;
  101.     type[1][1] = RED;
  102.     type[1][2] = GREEN;
  103.     type[1][3] = YELLOW;
  104.     type[1][4] = BLUE;
  105.    
  106.     type[2][0] = BLUE;
  107.     type[2][1] = YELLOW;
  108.     type[2][2] = GREEN;
  109.     type[2][3] = RED;
  110.     type[2][4] = BLUE;
  111.    
  112.     type[3][0] = GREEN;
  113.     type[3][1] = YELLOW;
  114.     type[3][2] = BLUE;
  115.     type[3][3] = RED;
  116.     type[3][4] = GREEN;
  117.    
  118.    
  119.     int x_1 = pos(lvl1, xd1, yd1);
  120.     int x_2 = pos(lvl2, xd2, yd2);
  121.     cout << (type[lvl1][x_1] == type[lvl2][x_2] ? "YES\n" : "NO\n");
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement