알고리즘 풀이/프로그래머스

프로그래머스 - [2020카카오공채] 기둥과 보 설치 (구현, 푸는중..)

배게 2019. 11. 26. 21:50
728x90

삭제 부분에 직감적으로 실수할 것 같아서 짬시키는중


============================================================


코드 다시 엎어서 2번째 도전햇는데도 37점인가가 한계였다

솔직히 카카오 너무 악랄한 것 같다


테케라도 5개정도 던져주던가 구글에 레퍼런스 코드가  있기는 했지만


이런 구현은 풀이법이 아니라 안틀리고 짜는 것이 중요하기 때문에 스스로 할 수 있다고


판단되므로 나중에 재도전해야겠다




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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 지금 하는 중인데 삭제부분이 문제다 하면서도
    // 구현하면서도 실수할 것 같은 예감이 든다 하기도 전에..
    public int[][] solution(int n, int[][] build_frame) {
        int[][] answer = {};
        
        int[][] pillar = new int[n+1][n+1];     // 기둥
        int[][] beam = new int[n+1][n+1];       // 보
        
        for(int i=0; i<build_frame.length; i++){         // 총 길이 k
            int x = build_frame[i][0];
            int y = build_frame[i][1];
            int structure = build_frame[i][2]; // 기둥/보 (0/1)
            int instOrDel = build_frame[i][3]; // 삭제/설치 (0/1)
            
            //기둥은 바닥 위에 있거나 보의 한쪽 끝 부분 위에 있거나, 또는 다른 기둥 위에 있어야 합니다.
            //보는 한쪽 끝 부분이 기둥 위에 있거나, 또는 양쪽 끝 부분이 다른 보와 동시에 연결되어 있어야 합니다.
            
            if(instOrDel==1){
                System.out.println("설치시작^^");
                if(structure == 0){
                    if(y==0 || beam[x][y]>=1 || pillar[x][y]>=1 ){
                        pillar[x][y]++;
                        pillar[x][y+1]++;
                    }
                }
                if(structure == 1){
                    if( pillar[x][y]>=1 || pillar[x+1][y]>=1 || (beam[x][y]>=1 && beam[x+1][y]>=1) ){
                        beam[x][y]++;
                        beam[x+1][y]++;
                    }
                }
            }
            else{
                System.out.println("삭제시작^^");
                
                if(structure == 0){
                    if( beam[x][y+1]==1 ){
//                        if(beam[x-1][y+1]==1 )
//                        if(beam[x-1][y+1]==0 && )
                        if( (beam[x-1][y]>=2 && beam[x+1][y]>=2)  ){
                            
                        }
                    }
                    // beam[x][y+1]>=2 delete가능..
                }
                
            }
            System.out.print(build_frame[i][0]+" ");
            System.out.print(build_frame[i][1]+" ");
            System.out.print(build_frame[i][2]+" ");
            System.out.print(build_frame[i][3]+" ");
            System.out.println();
        }
        
        for(int j=5; j>=0; j--){
            for(int i=0; i<n+1; i++){
                System.out.print(pillar[i][j]+" ");    
            }
            System.out.println();
        }
        System.out.println();
        
        for(int j=5; j>=0; j--){
            for(int i=0; i<n+1; i++){
                System.out.print(beam[i][j]+" ");    
            }
            System.out.println();
        }
        
        
        return answer;
    }
cs