관리 메뉴

피너클의 it공부방

백준 1531 투명 (c++) : 피너클 본문

백준

백준 1531 투명 (c++) : 피너클

피너클 2022. 7. 14. 13:11
728x90
반응형

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

 

1531번: 투명

첫째 줄에 N과 M이 주어진다. N은 0보다 크거나 같고, 50보다 작거나 같다. M은 0보다 크거나 같고, 50보다 작거나 같다. 둘째 줄부터 N개의 줄에 종이의 좌표가 주어진다. 왼쪽 아래 모서리의 x, y좌

www.acmicpc.net

간단한 구현문제다.

cin >> n >> m;
memset(map, 0, sizeof(map));

값을 입력받고 int map[101][101]을 0으로 초기화한다.

for (int i = 0; i < n; i++) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	for (int x = a; x <= c; x++) {
		for (int y = b; y <= d; y++) {
			map[x][y]++;
		}
	}
}

그후 투명용지의 좌표를 입력받고 그 범위 안의 map에 ++를 해준다.

int ans = 0;
for (int i = 1; i <= 100; i++) {
	for (int j = 1; j <= 100; j++) {
		if (map[i][j] > m) ans++;
	}
}
cout << ans << endl;

그후 맵을 하나씩 돌며 m보다 map[i][j]가 크다면 ans++를 하고

ans를 출력한다.

#include <iostream>
#include <cstring>

using namespace std;

int n, m;
int map[101][101];

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

	cin >> n >> m;
	memset(map, 0, sizeof(map));

	for (int i = 0; i < n; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		for (int x = a; x <= c; x++) {
			for (int y = b; y <= d; y++) {
				map[x][y]++;
			}
		}
	}

	int ans = 0;
	for (int i = 1; i <= 100; i++) {
		for (int j = 1; j <= 100; j++) {
			if (map[i][j] > m) ans++;
		}
	}
	cout << ans << endl;
}
728x90
반응형
Comments