No Rules Rules

네 번째 점 (feat. 백준, 3009번) 본문

생활/코테

네 번째 점 (feat. 백준, 3009번)

개발하는 완두콩 2022. 8. 3. 20:43
728x90
반응형

네 번째 점
https://www.acmicpc.net/problem/3009

 

3009번: 네 번째 점

세 점이 주어졌을 때, 축에 평행한 직사각형을 만들기 위해서 필요한 네 번째 점을 찾는 프로그램을 작성하시오.

www.acmicpc.net

반응형
// woohyeon.kim
// https://www.acmicpc.net/problem/3009
#include <iostream>
#include <map>
using namespace std;
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL);
	map<int, int> x_pos, y_pos;
	for (register int i = 0, x, y; i < 3; ++i)
		cin >> x >> y, ++x_pos[x], ++y_pos[y];
	register int x_ans = 0, y_ans = 0;
	for (auto& pos : x_pos)
		if (pos.second & 1) {
			x_ans = pos.first;
			break;
		}
	for (auto& pos : y_pos)
		if (pos.second & 1) {
			y_ans = pos.first;
			break;
		}
	cout << x_ans << " " << y_ans;
	return 0;
}
// *&)*@*
  1. 정사각형이라면 좌측 위의 점, 좌측 아래의 점, 우측 위의 점, 우측 아래의 점 4개에 대한 x,y가 각각 짝수여야 합니다.
  2. 즉, 입력받은 3개의 x,y에 대해서 홀수인 x와 y가 정답이 됩니다.
728x90
반응형
Comments