반응형

문제 출처 :


https://www.acmicpc.net/problem/2567



알고리즘 분석 :


문제 해결에 필요한 사항

1. 구현


이 문제를 풀때 색종이 외부를 카운트 해주면 된다.


그림으로 표현하면 아래와 같다.


□□□□□

□□□□□

□□□□□

□□□□□가 색종이라면


 ■■■■■

■□□□□□■

■□□□□□■

■□□□□□■

■□□□□□■

 ■■■■■


검정색 부분이 결국 색종이의 둘레가 된다.



소스 코드 : 


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
#include <iostream>
#include <cstdio>
 
using namespace std;
 
int arr[102][102];
 
int dy[4= { -1,0,1,};
int dx[4= { 0,-1,0,};
int main()
{
    int n;
    scanf("%d"&n);
 
    while (n--)
    {
        int x, y;
        scanf("%d %d"&y, &x);
 
        for (int i = y; i < y + 10; i++)
            for (int j = x; j < x + 10; j++)
                    arr[i][j] ++;
    }
 
    int ans = 0;
    for (int i = 0; i <= 100; i++)
        for (int j = 0; j <= 100; j++)
            if (arr[i][j] == 0)
                for (int k = 0; k < 4; k++)
                {
                    int ny = i + dy[k];
                    int nx = j + dx[k];
 
                    if ((<= ny && ny <= 100&& (<= nx && nx <= 100&& arr[ny][nx] >= 1)
                        ans++;
                }
 
    cout << ans;
 
    return 0;
}
 
//                                                       This source code Copyright belongs to Crocus
//                                                        If you want to see more? click here >>
Crocus

반응형

'Applied > 알고리즘 문제풀이' 카테고리의 다른 글

[15685번] 드래곤 커브  (0) 2018.04.28
[11663번] 선분 위의 점  (0) 2018.04.19
[14889번] 스타트와 링크  (0) 2018.04.14
[14501번] 퇴사  (0) 2018.04.12
[3190번] 뱀  (0) 2018.04.09