2023. 9. 22. 11:01 자기개발/코딩테스트
C++ (코딩테스트) - 넷이 놀기(백준)
문제
https://www.acmicpc.net/problem/2121
2121번: 넷이 놀기
첫 줄에 점들의 개수 N(5 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에 만들고 싶은 직사각형의 가로 길이 A(1 ≤ A ≤ 1,000)와 세로 길이 B(1 ≤ B ≤ 1,000)가 주어진다. 다음 N줄에 걸쳐서 점들의 좌표가 정수
www.acmicpc.net
내가 쓴 코드
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main(void) {
int N, W, H;
vector<pair<int, int>> list;
int x, y;
int cnt = 0;
cin >> N >> W >> H;
for (int i = 0; i < N; i++)
{
cin >> x >> y;
list.push_back(make_pair(x, y));
}
sort(list.begin(), list.end());
for (int lb = 0; lb < N-3; lb++)
{
//LB
int x1 = list[lb].first;
int y1 = list[lb].second;
bool chk = false;
//LT
int lt;
for (lt = lb + 1; lt < N - 2; lt++)
{
int x2 = list[lt].first;
int y2 = list[lt].second;
if (x2 == x1 && y2 == y1 + H) chk = true;
if (x2 > x1 || chk) break;
}
if (chk)
{
chk = false;
}
else
{
continue;
}
//RB
int rb;
for (rb = lt + 1; rb < N - 1; rb++)
{
int x3 = list[rb].first;
int y3 = list[rb].second;
if (x3 == x1 + W && y3 == y1) chk = true;
if (x3 > x1 + W || chk) break;
}
if (chk)
{
chk = false;
}
else
{
continue;
}
//RT
int rt;
for (rt = rb+1; rt < N; rt++)
{
int x4 = list[rt].first;
int y4 = list[rt].second;
if (x4 == x1 + W && y4 == y1 + H) chk = true;
if (x4 > x1 + W || y4 > y1 + H || chk) break;
}
if (chk) cnt++;
}
cout << cnt << endl;
return 0;
}
'자기개발 > 코딩테스트' 카테고리의 다른 글
C++ (코딩테스트) - 컵라면(백준) 우선순위 큐 사용 (0) | 2023.11.27 |
---|---|
C++ (코딩테스트) - 국영수(백준) : 정렬 (1) | 2023.11.01 |
C++ (코딩테스트) - 코코넛 그 두 번째 이야기(백준) (0) | 2023.09.22 |
C++ (코딩테스트) - 스텍(백준) (0) | 2023.09.20 |
C++ (코딩테스트) - 큐(백준) (0) | 2023.09.19 |