题解:P17827 [CSP-J 2026] 旅游 / travel(民间数据)

· · 题解

读题发现没有问左右关系。因此,可以把所有的 \texttt{D} 换成 \texttt{G}。作用如下:

  1. 所有相邻座位的字母在 ASCII 中也相邻,方便判断是否相邻;
  2. 加宽过道,方便区分是否为同一侧。

原来的座位位置:A B C 过道 D F。
修改后座位位置:A B C 加宽过道 F G。

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    string c1, s1, c2, s2;
    cin >> c1 >> s1 >> c2 >> s2;

    if (s1[2] == 'D') s1[2] = 'G';
    if (s2[2] == 'D') s2[2] = 'G';

    bool ans1 = (c1 == c2);
    bool ans2 = (ans1 && s1[0] == s2[0] && s1[1] == s2[1]);
    bool ans3 = (ans2 && abs(s1[2] - s2[2]) <= 2);
    bool ans4 = (ans2 && abs(s1[2] - s2[2]) == 1);

    cout << ans1 << ans2 << ans3 << ans4;

    return 0;
}