Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 개인프로젝트
- 프로그램
- C++
- 자바정리
- 풀스택프레임워크
- 모의 주식
- Reflex
- 코딩독학
- 개발자
- SNS
- 코딩테스트
- Project
- Python
- 이웃한 칸
- 자바
- 빅데이터
- frontend
- 백준
- 코스닥
- 사물인터넷
- 코딩
- 개발
- java
- java정리
- 프로그래밍
- 코테
- 프로그래머스
- 주가예측
- 자바독학
- backend
Archives
- Today
- Total
Creative Code
[10026번]적록색약 본문
https://www.acmicpc.net/problem/10026
10026번: 적록색약
적록색약은 빨간색과 초록색의 차이를 거의 느끼지 못한다. 따라서, 적록색약인 사람이 보는 그림은 아닌 사람이 보는 그림과는 좀 다를 수 있다. 크기가 N×N인 그리드의 각 칸에 R(빨강), G(초록)
www.acmicpc.net
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
int arr[101][101];
char arr1[101][101];
bool visit[101][101];
bool visit1[101][101];
int dx[] = { 0,1,0,-1 };
int dy[] = { -1,0,1,0 };
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
char c;
cin >> c;
arr1[i][j] = c;
if (c == 'R' || c == 'G') {
arr[i][j] = 1;
}
else {
arr[i][j] = 2;
}
visit[i][j] = false;
}
}
queue<pair<int, int>>q1;
vector<int>answer1;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (visit1[i][j] == false) {
answer1.push_back(1);
q1.push(make_pair(i, j));
while (!q1.empty()) {
int x = q1.front().first;
int y = q1.front().second;
q1.pop();
for (int k = 0; k < 4; k++) {
int nx = x + dx[k];
int ny = y + dy[k];
if (nx == -1 || ny == -1 || nx == N || ny == N || arr1[nx][ny] != arr1[x][y] || visit1[nx][ny] == true) {
continue;
}
else if (arr1[nx][ny] == arr1[x][y]) {
visit1[nx][ny] = true;
q1.push(make_pair(nx, ny));
}
}
}
}
}
}
cout << answer1.size() << '\n';
queue<pair<int, int>>q;
vector<int>answer;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (visit[i][j] == false) {
answer.push_back(1);
q.push(make_pair(i, j));
while (!q.empty()) {
int x = q.front().first;
int y = q.front().second;
q.pop();
for (int k = 0; k < 4; k++) {
int nx = x + dx[k];
int ny = y + dy[k];
if (nx == -1 || ny == -1 || nx == N || ny == N || arr[nx][ny] != arr[x][y] ||visit[nx][ny] == true) {
continue;
}
else if (arr[nx][ny] == arr[x][y]) {
visit[nx][ny] = true;
q.push(make_pair(nx, ny));
}
}
}
}
}
}
cout << answer.size() << '\n';
}
'백준 문제풀이' 카테고리의 다른 글
[16928번]뱀과 사다리 게임 (0) | 2023.09.24 |
---|---|
[12856번]평범한 배낭 (0) | 2023.09.24 |
[7576번]토마토 (0) | 2023.09.24 |
[7569번]토마토 (0) | 2023.09.24 |
[5430번]AC (0) | 2023.09.24 |