본문 바로가기

알고리즘 문제풀이153

[알고리즘/백준] 21608 상어 초등학교 - 자바(Java), 삼성 SW 역량테스트, 구현 문제 https://www.acmicpc.net/problem/21608 풀이 코드 구현 문제 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static int[] dx = {-1, 0, 1, 0}; static int[] dy = {0, 1, 0, -1}; static int n; static int[][] board, friends; /** * student 번 학생의 자리를 찾는 메서드 */ public static void solution(int student) { int maxEmp.. 2021. 10. 20.
[알고리즘/백준] 14503 로봇 청소기 - 자바(Java), 삼성 SW 역량테스트 기출 문제 https://www.acmicpc.net/problem/14503 풀이 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { static int[][] board; static int n, m, r, c, d; //dx[i], dy[i] : 현재 칸에서 i 방향으로 한칸 이동시 더해줄 x, y좌표 static int[] dx = {-1, 0, 1, 0}; static int[] dy = {0, 1, 0, -1}; public static int solution() { int answer = 0; while (t.. 2021. 10. 20.
[알고리즘/백준] 14500 테트로미노 - 삼성 SW 역량테스트, 자바(Java) 문제 https://www.acmicpc.net/problem/14500 풀이 코드 ㅜ 를 제외한 나머지 4개 모양은 DFS와 백트래킹을 통해 구한다. ㅜ 모양은 DFS를 통해 구할 수 없기 때문에 추가적으로 구한다.(코드상 checkOShape 메서드) import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { static int n, m; static int[][] board; static boolean[][] check; static int answer = Integer.MIN_VALUE; static int[] dx = .. 2021. 10. 18.
[알고리즘/백준] 14502 연구소 - 자바(Java), DFS, BFS, 삼성 SW 역량테스트 기출 문제 https://www.acmicpc.net/problem/14502 풀이 코드 DFS를 사용하여 벽을 놓을 위치를 찾는다. BFS를 사용하여 바이러스가 퍼지는 범위를 구하여 안전 영역을 구한다. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { static boolean[][] check; static int[][] board; static int n, m; static List virus; static int[] dx = {-1, 0, 1, 0}; static int[] dy = {0, 1, 0, -1}; sta.. 2021. 10. 17.
[2019 KAKAO BLIND RECRUITMENT] 오픈채팅방 - 자바(Java) 문제 https://programmers.co.kr/learn/courses/30/lessons/42888 풀이 코드 import java.util.*; public class Solution { static class Message { String status; String id; public Message(String status, String id) { this.status = status; this.id = id; } } public String[] solution(String[] record) { //리스트에 메시지의 종류(Enter 또는 Leave)와 id 값을 저장한다. List messages = new ArrayList(); //맵에 아이디와 그에 맞는 닉네임을 저장한다. Map map .. 2021. 10. 15.
[2020 KAKAO BLIND RECRUITMENT] 문자열 압축 - 자바(Java) 문제 https://programmers.co.kr/learn/courses/30/lessons/60057 풀이 코드 첫 풀이때 문자열의 길이가 1인 경우를 고려하지 못하여 풀이에 실패 했었다. 프로그래머스 채점시 테스트 5번만 실패한다면 문자열의 길이가 1인 경우를 확인해보자. public class Solution { public int solution(String s) { int answer = Integer.MAX_VALUE; //문자열 길이가 1인 경우 정답은 1 if(s.length() == 1) { return 1; } for(int i = 1; i 1) { sb.append(count); } sb.append(target); answer = Math.min(answer, sb.length(.. 2021. 10. 15.