Algorithm(44)
-
[programmers] 최소공배수와 최대공약수 (java) -1level
문제 설명 문제 해결 이 문제는 유클리드 호제법을 안다면 풀기 쉽다. public class 최대공약수와최소공배수 { public int[] solution(int n, int m) { // n, m 최대공약수와 최소공배수 를 구해라. int[] answer = new int[2]; int a = Math.max(n,m); // 둘 중에 더 큰 수 int b = Math.min(n,m); // 둘 중에 더 작은 수 while(b!=0){ int r = a%b; a = b; b = r; } answer[0] = a; answer[1] = n * m / a; // 두 수를 곱하고 최대 공약수로 나눠주면 최소공배수 return answer; } } 유클리드 호제법이란? 두 정수 a, b 가 있을 때 (a가 b..
2022.02.14 -
SWEA 5432번 - 쇠막대기 자르기
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Stack; public class Solution_쇠막대기자르기 { static int T; // 테케 static char[] crr; public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); Stack stack = new Stack(); T = Integer.parseInt(in.re..
2021.10.01 -
백준 11726번: 2xn 타일링
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; // 2xN 타일링 // 2xN 크기의 직사각형을 1x2, 2x1 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. public class Baekjoon11726 { static int[] DP; static int N; public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); N = Integer.parseIn..
2021.09.15 -
백준 2133번 : 타일 채우기 (java)
문제를 읽고 처음 dp 타일 연습문제와 비슷하다고 생각하여 쉽게 접근하였다. 하지만 fail 이 뜸. 잘 이해하지 못해서 해설 여러개를 보았다. 그 중에서 가장 이해가 잘 된 해설이다. [출처] https://fbtmdwhd33.tistory.com/79 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class Baekjoon2133 { static int[] dp; public static void main(String[] args) throws NumberFormatException, IOException { Buffered..
2021.09.15 -
백준 8958번: OX퀴즈
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Baekjoon_OX퀴즈 { static int N; public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); N = Integer.parseInt(in.readLine()); for (int i = 0; i < N; i++) { String[] str = in.readLine().split("")..
2021.08.31 -
백준 3052번: 나머지
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Baekjoon_나머지 { static int N; static int res; static int arr[]; public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); arr = new int[42]; for (int tc = 0; tc < 10; tc++) { N = Integer.parseIn..
2021.08.31