티스토리 뷰
https://www.acmicpc.net/problem/15240
15240번: Paint bucket
One of the most time-saving operations when drawing on a computer (for example using Photoshop) is the “bucket fill” operation. When you select this tool and click on a (target) pixel of the image it will fill all the pixels that have the same color
www.acmicpc.net
백준 소스코드 [C++] 15240 Paint bucket
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
using namespace std;
char arr[1002][1002];
bool check[1002][1002];
char cc,c;
queue <pair<int, int>> q;
pair<int, int> pp, p[4] = { {1,0},{-1,0},{0,1},{0,-1} };
void bfs() {
while (q.empty() != true) {
pp = q.front();
q.pop();
for (int i = 0;i < 4;i++) {
if (arr[pp.first + p[i].first][pp.second + p[i].second] == cc
&& check[pp.first + p[i].first][pp.second + p[i].second] == true) {
q.push(make_pair(pp.first + p[i].first, pp.second + p[i].second));
check[pp.first + p[i].first][pp.second + p[i].second] = false;
arr[pp.first + p[i].first][pp.second + p[i].second] = c;
}
}
}
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int x,y,a,b;
cin >> y >> x;
for (int j = 1;j <= y;j++)
for (int i = 1;i <= x;i++) {
cin >> arr[j][i];
check[j][i]=true;
}
cin >> a >> b >> c;
q.push(make_pair(a+1, b+1));
check[a+1][b+1] = false;
cc = arr[a + 1][b + 1];
arr[a + 1][b + 1] = c;
bfs();
for (int j = 1;j <= y;j++) {
for (int i = 1;i <= x;i++)
cout << arr[j][i];
cout << '\n';
}
return 0;
}'백준' 카테고리의 다른 글
| 백준 소스코드 [C++] 1753 최단경로 (0) | 2020.08.26 |
|---|---|
| 백준 소스코드 [C++] 16390 Sheba’s Amoebas (0) | 2020.08.26 |
| 백준 소스코드 [C++] 3184 양 (0) | 2020.08.25 |
| 백준 소스코드 [C++] 2468 안전 영역 (0) | 2020.08.25 |
| 백준 소스코드 [C++] 1697 숨바꼭질 (0) | 2020.08.24 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- mach-o
- 벨만포드 시간복잡도
- 부스트캠프 6기
- WWDC16
- 최단경로 알고리즘
- WWDC17
- 벨만포드 알고리즘
- 에드몬드 카프 알고리즘
- 네트워크 플로우
- 최단경로문제
- WWDC21
- State Restoration
- 다익스트라 시간복잡도
- Testable
- CPU와 Memory
- 컴퓨터 추상화
- HIG
- IOS
- 최단경로 문제
- 포드 풀커슨 알고리즘
- 강한 순환 참조
- WWDC19
- test coverage
- 네트워크 유량
- 코딩대회
- rxswift
- CompositionalLayout
- MeTal
- observeOn
- 최대 매칭
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함