문제

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;
}
Posted by pi92

블로그 이미지
pi92

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.5
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

최근에 올라온 글

최근에 달린 댓글

글 보관함