본문 바로가기

전체 글

(116)
파이썬 | 백준 | 1806 | 부분합 Solution # 1806, 부분합 import sys N, S = map(int, sys.stdin.readline().split()) arr = list(map(int, sys.stdin.readline().split())) start, end, sum = 0, 0, 0 min_ = 100001 while True: # sum이 s 이상이 되면 start를 하나 증가시킴 if sum >= S: sum -= arr[start] # start의 위치 1 증가 start += 1 min_ = min(min_, end - start + 1) # start~end까지가 현재 최소값보다 작으면 최소값 갱신 else: if end == N: # end=N되면 탐색 종료 break else: sum += arr[..
자바 | 백준 | 2096 | 내려가기 Solution. DP 이용 1열, 2열, 3열 각각 최소값, 최대값 구한다. // 2096, 내려가기 package BOJ; import java.io.*; import java.util.*; public class BOJ_2096 { static int N; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); N = Integer.parseInt(br.readLine()); int[][] map = new int[N + 1][3]; int[][] dp_max = new int[N + 1][3]; int[][] dp_..
자바 | 백준 | 1759 | 암호 만들기 Solution 조합 - C개 중 L개를 뽑아 자음 2개 이상, 모음 1개 이상이면 출력한다. 증가하는 순서로 배열되어 있으므로 sort 필요하다. // 1759, 암호 만들기 package BOJ; import java.io.*; import java.util.*; public class BOJ_1759 { static int L, C; static String[] alphas; static int[] combs; static StringBuilder sb = new StringBuilder(); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamRe..
자바 | 백준 | 1920 | 수 찾기 Solution 이분탐색 N의 값 큼 -> 이분 탐색 package BOJ; import java.io.*; import java.util.*; public class BOJ_1920 { static int N, M; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); N = Integer.parseInt(br.readLine()); int[] A = new int[N]; StringTokenizer st = new StringTokenizer(br..
자바 | 백준 | 3109 | 빵집 Solution 1. 오른쪽 위, 오른쪽, 오른쪽 아래 순서로 dfs 진행한다. // 3109, 빵집 package BOJ; import java.io.*; import java.util.*; public class BOJ_3109 { static int R, C; static char[][] board; static int[] dx = { -1, 0, 1 }; static int[] dy = { 1, 1, 1 }; static boolean flag; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTo..
파이썬 | 백준 | 2473 | 세 용액 Solution. 투 포인터 세 특성값 중 하나를 고정으로 두고 나머지 두 값을 가지고 투포인터.. # 2473, 세 용액 import sys N = int(sys.stdin.readline()) solution = list(map(int, sys.stdin.readline().split(" "))) solution.sort() diff = 3000000001 # 세 용액 특성값의 합 0에 가깝게 res = [] for i in range(len(solution) - 2): # 중복 체크 if i > 0 and solution[i] == solution[i - 1]: continue left = i + 1 right = len(solution) - 1 while left < right: sum = sol..
자바 | 백준 | 1874 | 스택 수열 | intValue() Solution 불가능한 경우: 스택의 peek()값이 큐의 peek() 값 보다 클 때 queue의 Integer값과 stk의 Integer값의 범위가 -128~127이 아닐 때, 비교 연산이 불가능하다. → intValue() - Returns the value of this Integer as an int. → stk.peek().intValue(), queue.peek().intValue() // 1874, 스택 수열 package BOJ; import java.io.*; import java.util.*; public class BOJ_1874 { public static void main(String[] args) throws IOException { // TODO Auto-generated ..
자바 | 백준 | 11866 | 요세푸스 문제 0 | LinkedList Solution 삭제가 계속 이루어짐 --> LinkedList 이용 // 11866, 요세푸스 문제 0 package BOJ; import java.io.*; import java.util.*; public class BOJ_11866 { public static void main(String[] args) throws IOException{ // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer st ..