Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 오에스
- 문제풀이
- 알고리즘
- 정석
- Stack
- 너비우선탐색
- 그래프
- 스택
- 코테
- bfs
- 컴공과
- 구현
- 오퍼레이팅시스템
- OS
- 백준
- 북리뷰
- c++
- 컴공
- 정석학술정보관
- DP
- 코딩
- coding
- cs
- 개발
- Computer science
- vector
- Operating System
- 컴퓨터공학과
- 브루트포스
- 자료구조
Archives
- Today
- Total
Little Jay
[C++][Project Euler] 코딩퀴즈 3번 - Full HD 화면상의 직사각형들이 차지하고 있는 총면적 본문
알고리즘/Project_Euler
[C++][Project Euler] 코딩퀴즈 3번 - Full HD 화면상의 직사각형들이 차지하고 있는 총면적
Jay, Lee 2022. 8. 25. 14:58간단한 bfs문제.
https://euler.synap.co.kr/quiz=3
입력받아야 하는 수가 좀 많아서 그렇지 bfs만 돌리면 간단하게 풀 수 있는 문제였다.
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int dx[] = { 1, -1, 0, 0 };
const int dy[] = { 0, 0, 1, -1 };
int display[1920][1080];
bool visited[1920][1080];
int bfs(int x, int y) {
visited[x][y] = true;
queue<pair<int, int>> q;
q.push({ x, y });
int size = 1;
while (!q.empty()) {
auto cur = q.front(); q.pop();
for (int i = 0; i < 4; i++) {
int nx = cur.first + dx[i];
int ny = cur.second + dy[i];
if (nx < 0 || ny < 0 || nx >= 1920 || ny >= 1080) continue;
if (visited[nx][ny]) continue;
if (display[nx][ny] != 1) continue;
q.push({ nx, ny });
visited[nx][ny] = true;
size++;
}
}
return size;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int x1, y1, x2, y2;
for (int i = 0; i < 1592; i++) {
cin >> x1 >> y1 >> x2 >> y2;
for (int x = x1; x < x2; x++) {
for (int y = y1; y < y2; y++) {
display[x][y] = 1;
}
}
}
int ans = 0;
for (int i = 0; i < 1920; i++) {
for (int j = 0; j < 1080; j++) {
if (!visited[i][j] && display[i][j] == 1) {
int size = bfs(i, j);
ans += size;
}
}
}
cout << ans << endl;
return 0;
}
'알고리즘 > Project_Euler' 카테고리의 다른 글
[Python][Project Euler] 코딩퀴즈 5번 - 숫자 목록을 이용해 만든 두 자연수 합의 최솟값 (0) | 2022.08.26 |
---|---|
[Python][Project Euler] 코딩퀴즈 1번 - '얼른 마스크'씨 회사 전기자동차의 행복한 일련번호 (0) | 2022.02.12 |
[Python][Project Euler] 코딩퀴즈 6번 - 특정 구간내의 모든 피보나치 수의 합 (0) | 2022.02.12 |
[Python][Projet Euler] 가장 큰 소인수 구하기 - 003 (0) | 2022.02.02 |
[Python][Projet Euler] 1부터 1000까지 영어로 썼을 때 사용된 글자의 개수는? - 017 (0) | 2022.01.27 |
Comments