公式

B - Pentagon 解説 by en_translator


Notice that there are only two kinds of lengths of segments.

Segments \(AB\), \(BC\), \(CD\), \(DE\), and \(EA\) are short, and the others are long. Thus, it is sufficient to determine if the given segment is short or not. See also the sample code.

(Note): a given segment is short if and only if the points are adjacent on \(P\). Finding the difference between characters eliminates conditional branches and simplifies implementation.

Sample code (C++):

#include <bits/stdc++.h>
using namespace std;

int main() {
	char a, b, c, d;
	cin >> a >> b >> c >> d;
	auto near = [](char x, char y) {
		if(x > y) swap(x, y);
		return y - x == 1 or y - x == 4;
	};
	if(near(a, b) == near(c, d))
		cout << "Yes\n";
	else
		cout << "No\n";
}

投稿日時:
最終更新: