구현(Implementation)
백준 2563번: 색종이
cepiloth
2018. 6. 13. 16:02
반응형
백준 2563번: 색종이
https://www.acmicpc.net/problem/2563
1. 문제 요약
100 x 100 크기에 도화지 위에 10 x 10 크기의 색종이를 붙쳤을 때 붙여진 색종이의 영역의 넓이를 구하는 문제
2. 알고리즘
100 x 100 2차원 배열을 선언하고 0 으로 초기화 한다.
종이를 붙이 x, y 위치를 입력 받고 x 부터 x +10, y 부터 y + 10 까지의 2차원 배열 요소에 1 로 초기화 한다.
모든 입력이 끝나면 2차원 배열을 순회하여 배열의 값이 1 인 수를 카운트하여 출력 한다.
3. 코드
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <functional> // greater 사용 위해 필요 #include <string> #include <map> #include <math.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int table[101][101] = {0,}; while(n--) { int x, y; cin >> x >> y; for(int i=x; i<x+10; i++) { for(int j=y; j<y+10; j++) { if (table[i][j] == 1) { continue; } else { table[i][j] = 1; } } } } int count = 0; for(int i=0; i<101; i++) { for(int j=0; j<101; j++) { if (table[i][j] == 1) { count ++; } } } cout << count << "\n"; return 0; } | cs |
반응형