paranid5

F

Jul 13th, 2020 (edited)
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. // Задача про шестиугольные шахматы из вступительной в МФТИ
  2.  
  3. #include <cstdio>
  4. #include <vector>
  5. #include <map>
  6. #include <algorithm>
  7.  
  8. std::map<char, int> max_high =
  9. {
  10.     {'a', 6},
  11.     {'b', 7},
  12.     {'c', 8},
  13.     {'d', 9},
  14.     {'e', 10},
  15.     {'f', 11},
  16.     {'g', 10},
  17.     {'h', 9},
  18.     {'i', 8},
  19.     {'k', 7},
  20.     {'l', 6},
  21. };
  22.  
  23. typedef std::pair<char, int> pci;
  24.  
  25. std::vector<pci> function(const pci fig)
  26. {
  27.     const int max_fig = max_high[fig.first];
  28.     std::vector<pci> p_fig;
  29.     for (int i = fig.second + 1; i <= max_fig; i++)
  30.     {
  31.         p_fig.emplace_back(fig.first, i);
  32.         //printf("1%c%d\n", fig.first, i);
  33.     } // C
  34.  
  35.     for (int i = fig.second - 1; i > 0; i--)
  36.     {
  37.         p_fig.emplace_back(fig.first, i);
  38.         //printf("2%c%d\n", fig.first, i);
  39.     } // Ю
  40.  
  41.     int second_ch = 0;
  42.     for (char i = fig.first - 1; i >= 'a'; i--)
  43.     {
  44.         if (i == 'j') i--;
  45.         pci x;
  46.         x.first = i;
  47.         if (x.first >= 'f') second_ch++;
  48.         x.second = fig.second + second_ch;
  49.         if (max_high[x.first] < x.second) break;
  50.         p_fig.push_back(x);
  51.         //printf("3%c%d\n", x.first, x.second);
  52.     } // СЗ
  53.  
  54.     second_ch = 0;
  55.     for (char i = fig.first + 1; i <= 'l'; i++)
  56.     {
  57.         if (i == 'j') i++;
  58.         pci x;
  59.         x.first = i;
  60.         if (x.first > 'f') second_ch++;
  61.         x.second = fig.second - second_ch;
  62.         if (x.second == 0) break;
  63.         p_fig.push_back(x);
  64.         //printf("4%c%d\n", x.first, x.second);
  65.     } // ЮВ
  66.  
  67.     second_ch = 0;
  68.     for (char i = fig.first + 1; i <= 'l'; i++)
  69.     {
  70.         if (i == 'j') i++;
  71.         pci x;
  72.         x.first = i;
  73.         if (x.first <= 'f') second_ch++;
  74.         x.second = fig.second + second_ch;
  75.         if (max_high[x.first] < x.second) break;
  76.         p_fig.push_back(x);
  77.         //printf("5%c%d\n", x.first, x.second);
  78.     } // СВ
  79.  
  80.     second_ch = 0;
  81.     for (char i = fig.first - 1; i >= 'a'; i--)
  82.     {
  83.         if (i == 'j') i--;
  84.         pci x;
  85.         x.first = i;
  86.         if (x.first < 'f') second_ch++;
  87.         x.second = fig.second - second_ch;
  88.         if (x.second == 0) break;
  89.         p_fig.push_back(x);
  90.         //printf("6%c%d\n", x.first, x.second);
  91.     } // ЮЗ
  92.     // перебрали все клетки, в которые может попасть фигура
  93.     return p_fig;
  94. }
  95.  
  96. int main()
  97. {
  98.     pci fig;
  99.     pci tar;
  100.     std::scanf("%c%d %c%d", &fig.first, &fig.second, &tar.first, &tar.second);
  101.     std::vector<pci> p_fig = function(fig);
  102.     std::vector<pci> p_tar = function(tar);
  103.     int ans = 0;
  104.     for (const auto& i : p_fig)
  105.         if (std::find(p_tar.begin(), p_tar.end(), i) != p_tar.end()) ans++;
  106.     std::printf("%d", ans);
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment