1236 성 지키기

2019. 8. 1. 17:09알고리즘/백준

해당 칸의 행과 열에 모두 없다면, 그 칸이 최우선순위가 된다. 그리고 다음 탐색에서는 하나라도 비어있는 칸을 채우면서 최소를 만들 수 있다

 

문제: https://www.acmicpc.net/problem/1236

깃허브주소: https://github.com/surinoel/boj/blob/master/1236.cpp

 

#include <iostream>
using namespace std;
char mat[50][50];
bool row[50];
bool col[50];
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> mat[i][j];
if (mat[i][j] == 'X') {
row[i] = col[j] = true;
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!row[i] && !col[j]) {
ans += 1;
row[i] = col[j] = true;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!row[i] || !col[j]) {
ans += 1;
row[i] = col[j] = true;
}
}
}
cout << ans << '\n';
return 0;
}
view raw 1236.cpp hosted with ❤ by GitHub

'알고리즘 > 백준' 카테고리의 다른 글

10174 펠린드롬  (0) 2019.08.03
1138 한 줄로 서기  (0) 2019.08.02
1543 문서 검색  (0) 2019.08.01
17363 우유가 넘어지면?  (0) 2019.07.31
4949 균형잡힌 세상  (0) 2019.07.31