티스토리 뷰
https://www.acmicpc.net/problem/1780
1780번: 종이의 개수
N×N크기의 행렬로 표현되는 종이가 있다. 종이의 각 칸에는 -1, 0, 1의 세 값 중 하나가 저장되어 있다. 우리는 이 행렬을 적절한 크기로 자르려고 하는데, 이때 다음의 규칙에 따라 자르려고 한다.
www.acmicpc.net
백준 소스코드 [C++] 1780 종이의 개수
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include<cstring>
using namespace std;
int arr[27*27*3+1][27*27*3+1];
int Minus = 0, zero = 0,Plus=0;
void dfs(int s, int g, int out, int arr[][27*27*3+1]) {
int p = 0,m=0,z=0;
for (int i = 1 + s;i <= s + out;i++)for (int j = 1 + g;j <= g + out;j++) {
if (arr[i][j] == 1) p++;
else if (arr[i][j] == -1) m++;
else z++;
}
if (p == out * out) {
Plus++; return;
}
else if (z == out * out) {
zero++; return;
}
else if (m == out * out) {
Minus++; return;
}
else {
for (int i = 0;i <= 2;i++)for (int j = 0;j <= 2;j++)
dfs(s + i * out / 3, g + j * out / 3, out / 3, arr);
}
}
int main() {
int n;
cin >> n;
for (int i = 1;i <= n;i++)for (int j = 1;j <= n;j++) cin >> arr[i][j];
dfs(0, 0, n, arr);
cout << Minus << '\n' << zero<<'\n'<< Plus;
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 2133 타일 채우기 (0) | 2020.08.17 |
---|---|
백준 소스코드 [C++] 1929 소수 구하기 (0) | 2020.08.17 |
백준 소스코드 [C++] 11051 이항 계수 2 (0) | 2020.08.17 |
백준 소스코드 [C++] 11047 동전 0 (0) | 2020.08.17 |
백준 소스코드 [C++] 7576 토마토 (0) | 2020.08.17 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- HIG
- mach-o
- 포드 풀커슨 알고리즘
- CompositionalLayout
- 최대 매칭
- observeOn
- WWDC19
- 벨만포드 시간복잡도
- 최단경로 알고리즘
- MeTal
- IOS
- 부스트캠프 6기
- rxswift
- WWDC16
- test coverage
- 벨만포드 알고리즘
- WWDC21
- State Restoration
- 코딩대회
- 최단경로문제
- 최단경로 문제
- 다익스트라 시간복잡도
- WWDC17
- 네트워크 유량
- 컴퓨터 추상화
- Testable
- CPU와 Memory
- 에드몬드 카프 알고리즘
- 강한 순환 참조
- 네트워크 플로우
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함