※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 12571번 문제인 Rope Intranet (Small)이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/12571 

 

12571번: Rope Intranet (Small)

The first line of the input gives the number of test cases, T. T test cases follow. Each case begins with a line containing an integer N, denoting the number of wires you see. The next N lines each describe one wire with two integers Ai and Bi. Th

www.acmicpc.net

12572번 문제(링크)에서 입력의 크기가 제한된 문제이다.

 

N이 1이면 두 와이어가 교차하는 경우가 존재할 수 없으므로 답은 0이 된다. 또한 N이 2이면 존재하는 두 와이어가 교차하는지의 여부를 확인해 답을 구해낼 수 있다. 이러한 관찰을 이용해 문제를 해결하자.

 

아래는 제출한 소스코드이다.

#include <iostream>
using namespace std;

int T, N;
int A1, B1, A2, B2;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> T;
	for (int t = 1; t <= T; t++) {
		cin >> N;

		int ans = 0;
		if (N == 1) cin >> A1 >> B1;
		else {
			cin >> A1 >> B1 >> A2 >> B2;
			if ((A1 - A2) * (B1 - B2) < 0) ans = 1;
		}

		cout << "Case #" << t << ": " << ans << '\n';
	}
}
728x90

+ Recent posts