[백준] Level IV. 빙산
·
Algorithm/백준
https://www.acmicpc.net/problem/2573  사용 알고리즘 BFS구현풀이 import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.*;public class Main { /* 1. 4분면에 있는 0의 개수만큼 값이 줄어듬 2. 두 덩어리로 분리되는 최초의 시간을 구함 */ static int n, m; static int [][] board; static int [][] tmp; static boolean[][] visited; static int[] dx = {1, 0, -1, 0};..
[프로그래머스] Lv.2 게임 맵 최단 거리
·
Algorithm/프로그래머스 코딩테스트 문제풀이전략
https://school.programmers.co.kr/learn/courses/30/lessons/1844BFS 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 사용 알고리즘BFS풀이import java.util.*;class Solution { static int [] dx = {1,0,-1,0}; static int [] dy = {0,1,0,-1}; public int solution(int[][] maps) { int n = maps.length; int m = maps[0].length; int [][] ..
[프로그래머스] Lv.3 단어 변환
·
Algorithm/프로그래머스 코딩테스트 문제풀이전략
https://school.programmers.co.kr/learn/courses/30/lessons/43163/ 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 사용 알고리즘BFSDFS풀이BFS를 사용한 풀이 import java.util.*;class Solution { public int solution(String begin, String target, String[] words) { int answer = 0; boolean [] visited = new boolean[words.length]; Qu..
[백준] Gold III. 감시
·
Algorithm/백준
https://www.acmicpc.net/problem/15683 사용 알고리즘DFS백트래킹풀이 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 int total = Integer.MAX_VALUE; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamRea..
[백준] Gold IV. 연구소
·
Algorithm/백준
https://www.acmicpc.net/problem/14502 사용 알고리즘DFS백트래킹풀이 import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.*;/* 1. 백트래킹과 BFS를 활용하는 문제같음 2. 길이가 3이 될때까지 벽을 모두 배치하고, 백트래킹을 돌면서 계속 넓이를 구함 3. 최댓값을 계속 갱신해줌 */public class Main { static int n, m; static int [][] board; static boolean [][] visited; static int [] dx = {1, 0, -1, 0}; stat..
[프로그래머스] Lv.2 기능개발
·
Algorithm/프로그래머스 코딩테스트 문제풀이전략
https://school.programmers.co.kr/learn/courses/30/lessons/42586 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr  사용 알고리즘배열 큐풀이 import java.util.*;class Solution { public int[] solution(int[] progresses, int[] speeds) { int [] complete = new int[progresses.length]; for(int i = 0; i list = new ArrayList(..
[프로그래머스] Lv.2 주식 가격
·
Algorithm/프로그래머스 코딩테스트 문제풀이전략
https://school.programmers.co.kr/learn/courses/30/lessons/42584 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr  사용 알고리즘 스택풀이 import java.util.*;class Solution { public int[] solution(int[] prices) { int[] answer = new int[prices.length]; // 1. 다음 값이 현재 값보다 작을 때 // 2. 다음 값이 현재 값보다 클 때 -> ..
[프로그래머스] Lv.2 괄호 회전하기
·
Algorithm/프로그래머스 코딩테스트 문제풀이전략
https://school.programmers.co.kr/learn/courses/30/lessons/76502 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 사용 알고리즘스택문자열 분할풀이 import java.util.Stack;class Solution { static int answer = 0; public int solution(String s) { for(int i = 0; i stack = new Stack(); for(char c : tmp.toCharArray()) { ..
[프로그래머스] Lv.2 올바른 괄호
·
Algorithm/프로그래머스 코딩테스트 문제풀이전략
https://school.programmers.co.kr/learn/courses/30/lessons/12909 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 사용 알고리즘스택풀이 import java.util.*;class Solution { boolean solution(String s) { Stack stack = new Stack(); for(char c : s.toCharArray()) { if (!stack.isEmpty()) { if (stack.peek..
N과 M 문제들 다시 풀어보기
·
Algorithm/백준
N과 M(1)1부터 N까지 자연수 중에서 중복 없이 M개를 고른 수열중복되는 수열을 여러 번 출력하면 안되며 -> boolean 배열을 사용해서 방문 체크 N과 M(2)고른 수열은 오름차순이어야 한다.위 조건으로 인해서 idx라는 파라미터가 추가되서 백트래킹을 돌리게 된다. 이전 문제에서 헷갈렸던 부분, i+1로 돌리느냐 idx + 1로 돌리느냐의 차이는 idx + 1로 돌리면, 현재 인덱스를 기준으로 다음 인덱스를 호출하기 때문에 항상 오름차순이지 않다. 하지만, i+1은 현재 요소를 기준으로 다음 요소를 선택하기 때문에 [1,2,3,4] -> 1을 다 순회했다면 다시 1을 사용하지 않아서 모두 오름차순이 된다.dfs(i + 1, depth + 1); N과 M(3)같은 수를 여러 번 골라도 된다.말그대..