전체 글 372

Extended Euclidean

Ax + By = C 방정식의 해를 구하는 것 - C % GCD(A, B) = 0인 경우에만 정수해를 가진다 (나누어 떨어질 때) - C의 최솟값은 1임을 적용하여 중간에서 MOD 연산 시작 예제 : 5x + 9y = 2 > 5x + 9y = 1 에서 시작 - 나머지가 0이 될때까지 연산 시행 MOD Remainder Quotient 5 % 9 = 5 5 0 9 % 5 = 4 4 1 5 % 4 = 1 1 1 4 % 1 = 0 0 4 - 최하단에서 역순으로 올라가며 x와 y 쌍 계산 x = 이전y y = 이전x - 이전y*Quotient * 최하단은 이전 값이 없으므로 이전값을 (1, 0)으로 지정 - 이렇게 재귀 형식으로 구해진 최종 (x, y)는 Ax + By = GCD(A, B)를 만족 - 또한 앞에..

Hard deck/Module 2022.08.04

(O.E Cable) BufferedWriter

// Input Supply Cable Scanner sc = new Scanner(System.in); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); // Preprocessing long A = sc.nextLong(); long B = sc.nextLong(); // Operating GCD long result = GCD(A, B); // Ouput Extracting Cable while (result > 0) { bw.write("1"); result--; } bw.flush(); bw.close(); 일반적인 출력을 수행하면 시간 초과가 발생할 수 있으므로 BufferedWriter를 사용합니다 *Buf..

Hard deck/Module 2022.08.04

Allocation and Spreaded out

전체 공간 > class point - point가 있어야 한다 - point의 크기가 있어야 한다(capacity) - point의 위상이 있어야 한다 - point의 형식이 있어야 한다 그리고... point가 어디로 흘러가는지 함수를 실행하고 나서, Output이 나가는지 나가지 않는지 민감할 것 for (int i = 0; i < T; i++) { // Preprocessing int A = sc.nextInt(); int B = sc.nextInt(); // Operating LCM int result = A*B / GCD(A, B); // Output Extracting Cable System.out.println(result); }

Hard deck/Deep dive 2022.08.04

045 : Extended Euclidean algorithm

(Briefing) 문제 단 하나의 맥락 입출력과 되어야 하는 그림 Ax + By = C 를 만족하는 (x, y) 쌍을 찾아라 I // A B C O // (존재x) -1 (존재) (x, y) import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { // Input Supply Cable BufferedReader br = new B..

Hard deck/리포트 2022.08.03