※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 12572번 문제인 Rope Intranet (Large)이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/12572
12572번: Rope Intranet (Large)
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
주어진 1000개의 와이어에서 두 개의 와이어를 고르는 경우의 수는 499,500가지로, 이는 모든 경우의 수를 직접 다 살펴 문제를 해결할 수 있을 정도로 충분히 적은 가짓수이다.
모든 와이어쌍에 대하여 둘이 교차하는지를 판단하고 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int T, N;
int X[1000], Y[1000];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
for (int t = 1; t <= T; t++) {
cin >> N;
for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if ((X[i] - X[j]) * (Y[i] - Y[j]) < 0) ans++;
}
}
cout << "Case #" << t << ": " << ans << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 3533 // C++] Explicit Formula (0) | 2022.12.10 |
---|---|
[BOJ 12571 // C++] Rope Intranet (Small) (0) | 2022.12.10 |
[BOJ 24080 // C++] 複雑な文字列 (Complex String) (0) | 2022.12.10 |
[BOJ 24803 // C++] Provinces and Gold (0) | 2022.12.09 |
[BOJ 7782 // C++] Alien (0) | 2022.12.09 |