2023.05.17.WED

ronglong·2023년 5월 17일
0

[ 백준 ]

  • 2178번 미로 탐색
    : 혼자서 해보다가 결국 해설 봤음.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    static int[][] matrix;
    static boolean[][] visited;
    static int[] dx = {0,1,0,-1};
    static int[] dy = {1,0,-1,0};
    static int N,M;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //선언

        //입력 값 받기
        StringTokenizer stringTokenizer = new StringTokenizer(br.readLine());
        N = Integer.parseInt(stringTokenizer.nextToken());
        M = Integer.parseInt(stringTokenizer.nextToken());

        //초기화
        matrix = new int[N][M];
        visited = new boolean[N][M];

        for(int i=0; i<N; i++){
            stringTokenizer = new StringTokenizer(br.readLine());
            String line = stringTokenizer.nextToken();
            for(int j=0; j<M; j++){
                matrix[i][j] = Integer.parseInt(line.substring(j, j+1));
            }
        }
        BFS(0,0);
        System.out.println(matrix[N-1][M-1]);
    }

    public static void BFS(int x, int y){
        Queue<int[]> queue = new LinkedList<>();
        queue.add(new int[]{x,y});

        while(!queue.isEmpty()){
            int[] now = queue.poll();
            visited[x][y] = true;
            for(int i=0; i<4; i++){
                int X = now[0] + dx[i];
                int Y = now[1] + dy[i];
                if(X >= 0 && Y >= 0 && X < N && Y < M){
                    if(!visited[X][Y] && matrix[X][Y]==1){
                        queue.add(new int[]{X,Y});
                        visited[X][Y] = true;
                        matrix[X][Y] = matrix[now[0]][now[1]] + 1;
                    }
                }
            }
        }
    }
}

[ 프로그래머스 ]

  • 게임 맵 최단거리
    : 윗 문제와 똑같은 문제가 있길래 혼자 풀어봤다. 이제 이 유형은 풀 수 있을 것 같다.
    BFS, DFS에서 정적 변수 쓰는 경우가 많고, 써보니 편하다.
import java.util.*;

class Solution {
    static int[][] A;
    static boolean[][] visited;
    static int[] dx = {0, 1, 0, -1};
    static int[] dy = {1, 0, -1, 0};
    static int n, m;

    public int solution(int[][] maps) {
        //초기화
        A = maps;
        n = maps.length;
        m = maps[0].length;
        visited = new boolean[n][m]; 

        BFS(0,0);

        return A[n-1][m-1]==1 ? -1 : A[n-1][m-1];
    }
    public static void BFS(int x, int y){
        Queue<int[]> queue = new LinkedList<>();
        queue.add(new int[]{x,y});
        visited[x][y] = true;

        while(!queue.isEmpty()){
            int[] now = queue.poll();
            for(int i=0; i<4; i++){
                int X = now[0] + dx[i];
                int Y = now[1] + dy[i];
                if(X >= 0 && Y >= 0 && X < n && Y < m){
                    if(!visited[X][Y] && A[X][Y]==1){
                        queue.add(new int[]{X,Y});
                        visited[X][Y] = true;
                        A[X][Y] = A[now[0]][now[1]] + 1;
                    }
                }
            }
        }
    }
}
  • 숫자의 표현
    : 분명 얼마 전에 백준에서 투 포인터로 풀었던 기억이 나는 똑같은 문제였다.
    그런데 계속 out of index 에러나서 이전에 풀었던 풀이 봄.
    투 포인터 + 합 배열로 접근했었는데, 합 배열은 대체 왜 생각났던 건지 모르겠음.
class Solution {
    public int solution(int n) {    
        int left = 1;
        int right = 1;
        int sum = 1;

        //n으로 n을 나타내는 경우 1 초기화
        int count = 1; 

        while(right != n){
            if(sum == n){
                count++;
                right++;
                sum += right;
            }
            if(sum < n){
                right++;
                sum += right;
            }
            if(sum > n){
                sum -= left;
                left++;
            }
        }
        return count;
    }
}

[ 유어클래스 다시 읽기 ]

  • section2. 스프링 AOP(Aspect Oriented Programming)
    • 코드 중복 최소화, 공통 기능 구현
    • 런타임 시에 프록시 객체 생성
    • 어드바이스(적용 시점), 조인포인트(메서드 호출), 포인트컷(적용 대상), 위빙
    • @EnableAspectJAutoProxy
      -> @Aspect가 붙은 Bean 객체의 포인트컷과 어드바이스 설정을 사용

[ 칼퇴족 김대리는 알고 나만 모르는 SQL ]

  • 필드 결합 : ||, +
  • TRIM()
  • 집계 함수는 NULL값을 무시하므로, AVG평균같은 경우 올바른 값을 구하기 위해서 COALESCE() 함수로 null을 0으로 초기화하는 것을 잊지 말 것!
  • SUBSTR(열 이름,시작 위치,총 자릿수)
  • ROUND(열 이름, 나타내고 싶은 소수 자리수)
  • SELECT _ , CASE WHEN 조건 THEN 결과 ELSE 결과 END AS _ FROM _ ;
  • SELECT _ , DECODE(열 이름 , 조건1, 결과1, 기본값) 새로운 열 이름 FROM _ ;

[ 느낀 점 ]

밤엔 photoday project 리팩토링 아주 조금 했다.
좀 더 자주 손대야지.

BFS, DFS는 조금씩 감을 잡아가고 있다. 하다보면 늘겠지.
AOP는 읽으면 어려운데, 경험상 차라리 한 번 해보는 게 더 낫다.
(분명 프로젝트에서 AOP 구현했었는데, 글로 읽으니까 넘 복잡스)

이번주 목표는 회사에 입사 지원하기★
매달 수많은 수료생들이 나오기 전에 얼른 시작하자~

✏️ 요즘 하고있는 공부들
: 유어 클래스 다시 읽기, 코테 연습, SQL 공부, CS 공부, photoday project 리팩토링, 이력서 준비

0개의 댓글