import java.io.*;import java.util.*;public class Solution { static int N; static double E; static long[][] islands; static int[] parent; static List edges; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int T = Integer.parseInt(br.rea..
[LG 유플러스] 유레카/코딩테스트
import java.util.*;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); int[] students = new int[N+1]; List> graph = new ArrayList(N+1); for(int i = 0; i ()); } for(int i = 0; i pq = new PriorityQueue(); for(int i = 1; i result = new ArrayList(); while(!pq.isEmpty()) { int cur = pq..
function solution(people, limit) { people.sort((a, b) => a - b); let left = 0; let right = people.length - 1; let boats = 0; while (left 몸무게 오름차순 정렬투 포인터 활용 (가장 가벼운 사람 + 가장 무거운 사람)left: 가장 가벼운 사람 (배열의 시작)right: 가장 무거운 사람 (배열의 끝)left + right가 limit 이하이면 두 사람을 함께 태움 → left++, right--초과하면 무거운 사람만 태움 → right--보트 개수 증가 (boats++)
function solution(k, dungeons) { let maxCount = 0; let visited = new Array(dungeons.length).fill(false); function dfs(fatigue, count) { maxCount = Math.max(maxCount, count); for (let i = 0; i = dungeons[i][0]) { visited[i] = true; dfs(fatigue - dungeons[i][1], count + 1); visited[i] = false; } } } dfs(k..
function solution(priorities, location) { let queue = priorities.map((priority, idx) => [priority, idx]); let count = 0; while (queue.length > 0) { let cur = queue.shift(); if (queue.some(process => process[0] > cur[0])) { queue.push(cur); } else { count++; if (cur[1] == location) { return count; } ..
function solution(progresses, speeds) { var answer = []; let queue = []; for (let i = 0; i 0) { let cur = queue.shift(); if (cur Math.ceil((100 - progresses[i]) / speeds[i])로 각 기능의 배포 완료 날짜를 구함모든 기능의 배포 날짜를 queue에 저장스택에서 하나씩 꺼내며 이전 배포 날짜와 비교하여 배포 가능한 기능을 하나의 그룹으로 묶음이전 배포 날짜보다 작거나 같은 날짜가 나오면 해당 그룹에 배포 가능한 기능을 추가그렇지 않으면, 배포 그룹을 answer 배열에 추가하고, 새로운 그룹을 시작while문을 빠져나오고 나서 마지..

내가 구현한 코드 (실패)function solution(n) { let q = []; let arr = []; arr[0] = 0; q.push(0); while(q.length > 0){ let cur = q.shift(); if(cur == n){ return arr[cur]; } if(arr[cur * 2] === undefined){ arr[cur * 2] = arr[cur]; q.push(cur * 2); } if(arr[cur + 1] === undefined){ arr[..
function solution(A,B){ var answer = 0; A.sort((a, b) => a-b); B.sort((a, b) => b-a); for(i = 0; i A는 최솟값부터, B는 최댓값부터 원소를 곱해서 answer에 더함
package cote;import java.util.Arrays;import java.util.Scanner;public class swea_2001_파리퇴치 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int i = 0; i 입력받은 N*N크기의 배열을 하나씩 탐색하면서 max값 갱신하는 방식
import java.util.*;public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); for(int i = 0; i 입력받은 상자들의 높이를 정렬최댓값에 -1, 최솟값에 +1 후 정렬을 덤프 횟수만큼 반복최댓값-최솟값 출력