Henu
개발냥발
Henu
전체 방문자
오늘
어제
  • 분류 전체보기 (411)
    • DevOps (52)
      • Kubernetes (19)
      • Docker (14)
      • AWS (3)
      • Nginx (4)
      • Linux (4)
      • ArgoCD (1)
      • CN (2)
      • NATS (0)
      • Git (5)
    • Back-End (30)
      • Django (18)
      • Spring (5)
      • JPA (1)
      • MSA (5)
    • CS (87)
      • SystemSoftware (20)
      • OS (25)
      • Computer Architecture (16)
      • Network (23)
      • Database (2)
    • Lang (21)
      • Java (9)
      • Python (4)
      • C# (8)
    • Life (12)
    • 블록체인 (2)
    • Algorithm (204)
      • BOJ (160)
      • 프로그래머스 (19)
      • LeetCode (4)
      • SWEA (1)
      • 알고리즘 문제 해결 전략 (8)
      • DS, algorithms (7)
      • Checkio (5)
    • IT (2)

블로그 메뉴

  • GitHub
  • 글쓰기
  • 관리자

공지사항

  • Free!

인기 글

태그

  • Kubernetes
  • django
  • 프로그래머스
  • 백트래킹
  • docker
  • DFS
  • BFS
  • boj
  • 다이나믹 프로그래밍
  • Network

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Henu

개발냥발

[SWEA 1206] View (D3)
Algorithm/SWEA

[SWEA 1206] View (D3)

2021. 7. 19. 01:44
 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

1000*255 = 25만 밖에 안되고, test case도 10개 뿐이므로 문제에서 주어진 아파트를 배열에 모두 구현하는 방법을 사용했다.

현재 아파트의 현재 층에서 좌우로 1, 2개 의 칸이 비어있다면 조망권이 있는 집으로 분류했다.

 

아파트의 구조를 2차원 배열에 담지않고 [1000]인 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#define fasti ios_base::sync_with_stdio(false); cin.tie(0);
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1e9+7
#define pii pair<int, int>
 
typedef long long ll;
// typedef pair<int, int> pii;
 
using namespace std;
 
int N, test, t;
int house[1001][256];
 
void input(){
    memset(house, 0, sizeof(house));
    int H;
    cin >> N;
    for(int i = 1; i <= N; i++){
        cin >> H;
        for(int k = 1; k <= H; k++){
            house[i][k] = 1;
        }
    }
}
 
void solve(){
    int res = 0;
    
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= 255; j++){
            if(!house[i][j]) break;
            
            if(!house[i-1][j] && !house[i-2][j] && !house[i+1][j] && !house[i+2][j]){
                res += 1;
            }
        }
    }
    
    cout << "#" << t << " " << res << "\n";
}
 
int main(int argc, char** argv){
    t = 1;
    test = 10;
    while(t <= test){
        input();
        solve();
        t++;
    }
    
    return 0;
}
 
Colored by Color Scripter
cs

 

    티스토리툴바