티스토리 뷰
https://www.acmicpc.net/problem/1018
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
vector<vector<char>> ChessBoard;
int N, M, max;
//입력
cin >> N >> M;
for (int i = 0; i < N; i++) {
vector<char> temp;
for (int j = 0; j < M; j++) {
char x;
cin >> x;
temp.push_back(x);
}
ChessBoard.push_back(temp);
}
max = N * M;
//8*8크기의 체스판으로 만들기 (최소의 색칠로)
for (int i = 0; i < N - 7; i++) {
for (int j = 0; j < M - 7; j++) {
//8*8 체스판의 시작점은 ( i , j )
int Wmod = 0, Bmod = 0;
//시작점이 W일때는 x+y 가 짝수면 W / 홀수면 B
//시작점이 B일때는 x+y 가 홀수면 W / 짝수면 B
for (int x = i; x < i + 8; x++) {
for (int y = j; y < j + 8; y++) {
if ((x + y) % 2 == 0) { //짝수칸(시작지점과 같은색이어야 하는 칸)
if (ChessBoard[x][y] != 'W')
Wmod++;
else
Bmod++;
}
else { //홀수칸(시작지점과 다른색의 칸)
if (ChessBoard[x][y] != 'B')
Wmod++;
else
Bmod++;
}
}
}
if (max > min(Wmod, Bmod))
max = min(Wmod, Bmod);
}
}
cout << max << endl;
}
'Algorithm > 유형별 : simulation' 카테고리의 다른 글
[C++] [Simulation] 백준 3190번 : 뱀 (0) | 2019.11.14 |
---|---|
[C++] [Simulation] 백준 14499번 : 주사위 굴리기 (0) | 2019.11.14 |
[C++] [Simulation] 백준 14503번 : 로봇 청소기 (0) | 2019.11.14 |
[C++] [Simulation] 백준 1966번 : 프린터 큐 (0) | 2019.11.14 |
[C++] [Simulation] 백준 1094번 : 막대기 (0) | 2019.11.14 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Update
- java
- 객체
- 다형성
- JdbcTemplate
- view
- java 환경설정
- Scott/Tiger
- controller
- jdbc
- INSERT
- 객체지향
- 캡슐화
- Delete
- MVC
- JDBC 프로그램 작성단계
- 상속
- model
- Oracle
- ojdbc6.jar
- 추상화
- .
- select
- OOP
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함