본문 바로가기

알고리즘문제풀이

(7)
[Java] LeetCode 문제 풀이 : Problem1 Two Sum (Array) ---문제--- Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. interger 로 구성된 배열 nums 와 interger 숫자 target 이 주어졌을 때, nums 에 포함된 숫자들 중 더해서 target 숫자가 될 수 있는 숫자 2개의 index를 반환하는 코드를 짜시오..
[Java] 백준 알고리즘 2512번 문제 (이분 탐색) ---문제--- ---코드--- import java.util.Scanner; public class Bj2512 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] req = new int[N]; int sum = 0; int max_value = 0; int min_value = 100001; for (int i = 0; i max_value) max_value = req[i]; if ..
[Java] 백준 알고리즘 1654번 문제 (이분 탐색) ---문제--- ---코드--- import java.util.Arrays; import java.util.Scanner; public class Bj1654 { public static long max_result; public static long[] lines; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int K = sc.nextInt(); long N = sc.nextInt(); lines = new long[K]; for(int i=0; i lines[K-2])? lines[K-1]/2 : lines[K-2]); return; } else { long left = lines[K-1]/N ; long..
[Java] SW Expert Academy 1289번 문제 (문자열) ---문제--- 1289. 원재의 메모리 복구하기 ---코드--- import java.util.Scanner; class Solution { public static void main(String[] args) { //System.setIn(new FileInputStream("1289.txt")); Scanner sc = new Scanner(System.in); int T; T=sc.nextInt(); for(int test_case = 1; test_case
[Java] SW Expert Academy, SW 상시 역량테스트 모의 테스트 1767번 문제 (완전 탐색, DFS, 깊이 우선 탐색) ---문제--- 1767. [SW Test 샘플문제] 프로세서 연결하기 ---코드--- 이 경우는, 한 node를 지나가면 또 다른 후보가 나오고 그 후보들을 차례로 보고 다음 또 후보가 나오는 bfs(너비 우선 방식)방식 보다는, 각자의 node에서의 가능성을 판단하고 일단 이 경우에서 다음 node로 넘어가는 연쇄적인 방식을 반복하는 dfs의 구현이 더욱 가능성 있다고 판단하였는데, 그 이유는 그렇게 해야 앞에서의 완성형의 (가능한 모든 core를 연결한 경우) 최댓값, 최솟값을 알 수 있고 이를 이용하면 마치 분기한정(Branch & Bound) 처럼 탐색의 갯수를 줄일 수 있었기 때문입니다. (기저사례 1번 참고) import java.util.ArrayList; import java.util.S..
[Java] SW Expert Academy 1486번 문제 (완전 탐색, DFS, 깊이 우선 탐색) ---문제--- 1486. [모의 SW 역량테스트] 장훈이의 높은 선반 ---코드--- import java.util.Scanner; import java.io.FileInputStream; public class Sw1486 { static int N, B; static int[] tall; static int result, subresult; public static void main(String args[]) throws Exception { //System.setIn(new FileInputStream("1486.txt")); Scanner sc = new Scanner(System.in); int T; T = sc.nextInt(); for (int test_case = 1; test_case ..
[Java] SW Expert Academy 5658번 문제 (문자열) ---문제--- 5658. [모의 SW 역량테스트] 보물상자 비밀번호 ---코드--- import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; import java.util.Scanner; import java.io.FileInputStream; import java.io.FileNotFoundException; public class Sw5658 { public static void main(String[] args) throws FileNotFoundException { //System.setIn(new FileInputStream("5658.txt")); Scanner sc = new Scanner(..

728x90
반응형