[스터디] Java 알고리즘 2문제 (25.02.25)
·
LG 유플러스 유레카 SW/스터디
1. 백준 2252 - 줄 세우기위상 정렬 활용import java.util.ArrayList;import java.util.LinkedList;import java.util.List;import java.util.Queue;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); List> graph = new ArrayList(); for(int i = 0; i ()); } int[] inDegree = new int[N+1]; for..
[스터디] MST 2문제 출제 및 풀기 + 도전 문제 2문제 (25.02.24)
·
LG 유플러스 유레카 SW/스터디
MST 문제 출제1. 우주 정거장 건설 문제우주 탐사선들이 정거장을 세우기 위해 N개의 행성에 기지를 건설하려 한다.각 행성은 (x, y) 좌표를 가지며, 두 행성을 연결하는 비용은 유클리드 거리로 정의된다.모든 행성을 최소 비용으로 연결하는 프로그램을 작성하시오.📍 입력 형식N (행성 개수)N개의 줄: x y (각 행성의 좌표)📍 출력 형식최소 신장 트리의 총 비용을 출력하시오.예제 입력41 12 22 45 6예제 출력7.02 (소수점 2번째 자리까지 출력) ➡️ Kruskal 알고리즘 풀이package algo_250224;import java.util.ArrayList;import java.util.Collections;import java.util.List;import java.util.Sca..
[스터디] Java 알고리즘 2문제 (25.02.21)
·
LG 유플러스 유레카 SW/스터디
1. 백준 1697 - 숨바꼭질BFS로 최단 경로 찾기N(0 ≤ N ≤ 100,000), K(0 ≤ K ≤ 100,000) 범위 내에서 조건 처리순간이동, 전진, 후진의 3가지 조건import java.util.LinkedList;import java.util.Queue;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt(); boolean[] visited = new boolean[100001]; Queue q = new LinkedList(); int ..
[스터디] Java 도전 문제 3문제 (25.02.20)
·
LG 유플러스 유레카 SW/스터디
1. 백준 17478 - 재귀함수가 뭔가요?import java.util.Scanner;public class Main { static int n; public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); System.out.println("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다."); print(0); sc.close(); } static void print(int cur) { if(n == cur) { System.out.print("____".repeat(cur)); System.out.println("\"재귀함수가 뭔가요?\""); ..
[스터디] Java 프로그래머스 PCCE 기출 14문제 (25.02.19)
·
LG 유플러스 유레카 SW/스터디
1. 산책class Solution { public int[] solution(String route) { int east = 0; int north = 0; int[] answer = new int [2]; for(int i=0; i2. 저축import java.util.Scanner;public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int start = sc.nextInt(); int before = sc.nextInt(); int after = sc.nextI..
[스터디] Java 프로그래머스 기초 24문제 & 머쓱이 획득 (25.02.18)
·
LG 유플러스 유레카 SW/스터디
1. qr codeclass Solution { public String solution(int q, int r, String code) { String answer = ""; for(int i=0;i2. 수열과 구간 쿼리 4class Solution { public int[] solution(int[] arr, int[][] queries) { for(int[] q:queries){ int s=q[0]; int e=q[1]; int k=q[2]; for(int i=s;i3. 특수문자 출력하기import java.util.Scanner;public class Main { p..
[스터디] Java 프로그래머스 기초 30문제 (25.02.17)
·
LG 유플러스 유레카 SW/스터디
1. 두 수의 연산값 비교하기class Solution { public int solution(int a, int b) { String n1 = a + "" + b; int n2 = 2 * a * b; return Integer.parseInt(n1) > n2 ? Integer.parseInt(n1) : n2; }}2. 문자열로 변환class Solution { public String solution(int n) { String answer = ""; return answer + n; }}3. flag에 따라 다른 값 반환하기class Solution { public int solution(int a..
[스터디] Java 프로그래머스 기초 30문제 (25.02.14)
·
LG 유플러스 유레카 SW/스터디
1. 수 조작하기 1class Solution { public int solution(int n, String control) { for(String c:control.split("")) { switch(c) { case "w": n += 1; break; case "s": n -= 1; break; case "d": n += 10; break; ..