240707

Regular Kim·2024년 7월 7일
0

회고

목록 보기
48/59

240707 회고 💬

장마와 함께 7월이 시작됐다. 역대급 장마라고 뉴스에 많이 나오던데 생각보다 비가 그리 세차게 오지는 않는다. 비가 오던, 눈이 오던 할 일은 해야겠지... 7월 첫째 주를 되돌아본다.

Keep 👍

  • 알고리즘 문제 풀이를 7일 연속으로 해냈다. 이번 주에는 골드 문제에 몇가지 도전해봤다. 브론즈 문제만 300개 넘게 풀었다보니 실버도 그렇게 하고싶은데 골드 난이도에 재밌는 문제가 많아서 균형을 잡는데 신경쓰고 있다.
    - 연구소 벽을 3개 짓고 안전한 영역의 넓이를 구하는 문제다. 벽을 만들 때는 DFS를 사용하고, 안전 구역 넓이를 구할 때는 BFS를 사용한다. 둘 다 사용할 생각을 처음에 못해서 벽을 다중 for문으로 지으려고 했었다. 백트래킹을 공부했다면 금방 벽 짓는 방법을 이해할 수 있다.
    - 국영수 정렬 문제다. 정렬 알고리즘을 코딩할 필요는없다. 객체에 정렬 기준을 만들어주고, 그 기준대로 정렬 함수를 적용하면 된다. Comparable 구현만 할 줄 안다면 금방 해결할 수 있는 문제다.
  • 이번 주에는 스프링 데이터 JPA를 공부했다. 그리고 약간의 servlet 복습도 진행했다. 쿼리 매소드, Auditing 등을 공부했다.

Try 🧚

  • 스프링 MVC 구조 공부하기
  • 컨트롤러 어드바이스 공부하기
  • AWS 배포 준비하기

Extras 😀

연구소


import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

            Solution s = new Solution();
            System.out.println(s.solution(getInput(br)));

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private static int[][] getInput(BufferedReader br) throws IOException {
        int[] tokens = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[][] board = new int[tokens[0]][tokens[1]];

        for (int i = 0; i < board.length; i++) {
            board[i] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        }
        return board;
    }
}

class Solution {

    public int solution(int[][] board) {
        Calculator c = new Calculator(board);
        return c.getResult();
    }

    private class Calculator {

        int[][] boardOrigin;
        Queue<Virus> qOrigin = new ArrayDeque<>();
        int result = 0;
        int[][] directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

        public Calculator(int[][] boardOrigin) {
            this.boardOrigin = boardOrigin;
            virusInit();
        }

        public int getResult() {
            explore();
            return result;
        }

        private void explore() {
            buildWalls(0);
        }

        private void buildWalls(int cnt) {
            if (cnt == 3) {
                infectAndCalc();
                return;
            }

            for (int i = 0; i < boardOrigin.length; i++) {
                for (int j = 0; j < boardOrigin[i].length; j++) {
                    if (boardOrigin[i][j] == 0) {
                        boardOrigin[i][j] = 1;
                        buildWalls(cnt + 1);
                        boardOrigin[i][j] = 0;
                    }
                }
            }
        }

        private void infectAndCalc() {
            int[][] board = copy();
            Queue<Virus> q = new ArrayDeque<>(qOrigin);

            while (!q.isEmpty()) {
                Virus current = q.poll();

                for (int[] direction : directions) {
                    int nx = current.x + direction[0];
                    int ny = current.y + direction[1];

                    if (isWithinBoard(nx, ny) && board[nx][ny] == 0) {
                        board[nx][ny] = 2;
                        q.offer(new Virus(nx, ny));
                    }
                }
            }
            getSafeZone(board);
        }

        private void getSafeZone(int[][] board) {
            int temp = 0;
            for (int i = 0; i < board.length; i++) {
                for (int j = 0; j < board[i].length; j++) {
                    if (board[i][j] == 0) temp++;
                }
            }
            result = Math.max(result, temp);
        }

        private boolean isWithinBoard(int x, int y) {
            return 0 <= x && x < boardOrigin.length && 0 <= y && y < boardOrigin[x].length;
        }

        private int[][] copy() {
            int[][] result = new int[boardOrigin.length][boardOrigin[0].length];
            for (int i = 0; i < result.length; i++) {
                result[i] = boardOrigin[i].clone();
            }
            return result;
        }

        private void virusInit() {
            for (int i = 0; i < boardOrigin.length; i++) {
                for (int j = 0; j < boardOrigin[i].length; j++) {
                    if(boardOrigin[i][j] == 2) qOrigin.add(new Virus(i, j));
                }
            }
        }

        private class Virus {
            int x;
            int y;

            public Virus(int x, int y) {
                this.x = x;
                this.y = y;
            }
        }
    }
}

국영수


import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

            Solution s = new Solution();
            System.out.println(s.solution(getInput(br)));
            
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private static Map<String, int[]> getInput(BufferedReader br) throws IOException {
        Map<String, int[]> result = new HashMap<>();
        int len = Integer.parseInt(br.readLine());
        for (int i = 0; i < len; i++) {
            String[] tokens = br.readLine().split(" ");
            String name = tokens[0];
            int korean = Integer.parseInt(tokens[1]);
            int english = Integer.parseInt(tokens[2]);
            int math = Integer.parseInt(tokens[3]);
            result.put(name, new int[]{korean, english, math});
        }
        return result;
    }
}

class Solution {

    public String solution(Map<String, int[]> students) {
        Student[] result = new Student[students.size()];

        int idx = 0;
        for (String name : students.keySet()) {
            int[] scores = students.get(name);
            int korean = scores[0];
            int english = scores[1];
            int math = scores[2];
            result[idx++] = new Student(name, korean, english, math);
        }
        Arrays.sort(result);

        return getResult(result);
    }

    private String getResult(Student[] students) {
        StringBuilder result = new StringBuilder();
        for (Student s : students) {
            result.append(s.name).append("\n");
        }
        return result.toString();
    }

    private class Student implements Comparable<Student> {
        String name;
        int korean;
        int english;
        int math;

        public Student(String name, int korean, int english, int math) {
            this.name = name;
            this.korean = korean;
            this.english = english;
            this.math = math;
        }

        @Override
        public int compareTo(Student o) {
            if (this.korean == o.korean && this.english == o.english && this.math == o.math) {
                return this.name.compareTo(o.name);
            } else if (this.korean == o.korean && this.english == o.english) {
                return o.math - this.math;
            } else if (this.korean == o.korean) {
                return this.english - o.english;
            } else {
                return o.korean - this.korean;
            }
        }
    }
}

서평 완료 목록

서평 예정 목록 (읽는 중)

  • 프로그래머의 길, 멘토에게 묻다
  • 함께 자라기 애자일로 가는 길

독서 예정 목록

목록은 우선순위 큐이다. 상단에 있더라도 더 중요한 책이 들어온다면 순위가 뒤로 밀릴 수 있다.

  • 객체지향의 사실과 오해
  • 오브젝트
  • 파이브 라인스 오브 코드
  • HTTP 완벽 가이드
  • 자바/스프링 개발자를 위한 실용주의 프로그래밍
  • 모던 자바 인 액션
  • 자바 성능 튜닝 이야기
  • 자바 개발자와 시스템 운영자를 위한 트러블 슈팅 이야기 / scouter를 활용한 시스템 장애 진단 및 해결 노하우 자바 트러블슈팅
  • 헤드 퍼스트 서블릿
  • Hello Coding 그림으로 개념을 이해하는 알고리즘
profile
What doesn't kill you, makes you stronger

0개의 댓글