알고리즘
-
18258 - 큐2알고리즘 2023. 5. 24. 22:49
https://www.acmicpc.net/problem/18258 18258번: 큐 2 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 2,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayDeque; public class Main { public static void main(String[] args) throws IOException { Buffere..
-
10773 - 제로알고리즘 2023. 5. 24. 22:27
https://www.acmicpc.net/problem/10773 10773번: 제로 첫 번째 줄에 정수 K가 주어진다. (1 ≤ K ≤ 100,000) 이후 K개의 줄에 정수가 1개씩 주어진다. 정수는 0에서 1,000,000 사이의 값을 가지며, 정수가 "0" 일 경우에는 가장 최근에 쓴 수를 지우고, 아닐 경 www.acmicpc.net import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Stack; public class Main { public static void main(String[] args) throws IOException { Buffere..
-
1002 - 터렛알고리즘 2023. 5. 24. 22:21
https://www.acmicpc.net/problem/1002 1002번: 터렛 각 테스트 케이스마다 류재명이 있을 수 있는 위치의 수를 출력한다. 만약 류재명이 있을 수 있는 위치의 개수가 무한대일 경우에는 -1을 출력한다. www.acmicpc.net 문제요약 레이더의 두 점의 좌표와 좌표로부터 멀어질 수 있는 거리가 주어짐 두 레이더가 만나는지 여부를 파악하는 문제 두점에서만나면 2, 한 점에서 만나면 1, 만나지 않으면 0, 모든 거리에서 만나면, -1 을 출력 두 원의 접점을 구하는 문제 경우의 수를 나누는 것이 핵심 1 - x : 주 중심의 거리(피타고라스)와 반지름들의 합 과의 비교 2 - x : 두 중심의 거리(|a - b|)와 반지금들의 합과의 비교 import java.util.Sc..
-
1011 - Fly me to the Alpha Centauri알고리즘 2023. 5. 24. 21:18
https://www.acmicpc.net/problem/1011 1011번: Fly me to the Alpha Centauri 우현이는 어린 시절, 지구 외의 다른 행성에서도 인류들이 살아갈 수 있는 미래가 오리라 믿었다. 그리고 그가 지구라는 세상에 발을 내려 놓은 지 23년이 지난 지금, 세계 최연소 ASNA 우주 비행 www.acmicpc.net 문제요약 첫출발은 1 (k) 다음 출발은 -1, 0, 1 (k - 1), k, (k + 1) 로 움직일 수 있다. 도착지에 도착할 때는 무조건 1 0 ≤ x < y < 231 출발지에서 도착지까지 최소한의 이동 횟수를 출력 이동 루트 거리 처음 등장 하는 숫자가 나타날때의 거리 처음 등장하는 숫자와 거리와의 관계 1 1 1 1 1 2 1 1 1 3 1 ..
-
1110 - 더하기 사이클알고리즘 2023. 5. 24. 21:02
https://www.acmicpc.net/problem/1110 1110번: 더하기 사이클 0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자리 수로 만들고, 각 자리의 숫자를 더한다. 그 다음, www.acmicpc.net 문제요약 주어진 숫자의 각 자릿수를 더한다 ( 10 보다 작은 숫자는 앞자리에 0을 더하고 시작 ) 더한 숫자의 1의 자리와 더해진 숫자의 1의 자리를 다시 합쳐 새로운 숫자를 만든다. 반복... 처음의 숫자가 나오기까지의 몇 번을 반복했는지 확인한다. import java.io.BufferedReader; import java.io.IOException; import java.io..
-
1929 - 소수 구하기알고리즘 2023. 5. 24. 20:50
https://www.acmicpc.net/problem/1929 1929번: 소수 구하기 첫째 줄에 자연수 M과 N이 빈 칸을 사이에 두고 주어진다. (1 ≤ M ≤ N ≤ 1,000,000) M이상 N이하의 소수가 하나 이상 있는 입력만 주어진다. www.acmicpc.net 문제요약 M이상 N이하의 소수를 모두 출력 1 ≤ M ≤ N ≤ 1,000,000 import java.io.*; public class Main { public static boolean[] getPrime() { int num = 1000000; boolean[] arr = new boolean[num + 1]; // 1은 소수 아님 arr[1] = true; for (int i = 2; i * i < arr.length; ..
-
10250 - ACM 호텔알고리즘 2023. 5. 24. 20:43
https://www.acmicpc.net/problem/10250 10250번: ACM 호텔 프로그램은 표준 입력에서 입력 데이터를 받는다. 프로그램의 입력은 T 개의 테스트 데이터로 이루어져 있는데 T 는 입력의 맨 첫 줄에 주어진다. 각 테스트 데이터는 한 행으로서 H, W, N, 세 정수 www.acmicpc.net 문제요약 H(높이) W(넓이)와 N(몇번 째 방) 엘레베이터에서 가까운 순으로, 만약 동일한 거리라면, 낮은 층으로 배정 import java.util.Scanner; public class Main { public static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int T = sc..
-
2869 - 달팽이는 올라가고 싶다알고리즘 2023. 5. 23. 12:21
https://www.acmicpc.net/problem/2869 2869번: 달팽이는 올라가고 싶다 첫째 줄에 세 정수 A, B, V가 공백으로 구분되어서 주어진다. (1 ≤ B < A ≤ V ≤ 1,000,000,000) www.acmicpc.net 문제요약 달팽이가 낮에 A만큼 올라감. V 높이에 도달하면, 더이상 미끄러지지 않는다. 도달못한다면, 밤에 B만큼 미끄러진다. 1 ≤ B < A ≤ V ≤ 1,000,000,000 달팽이가 V 높이까지 올라가는데 걸리는 날을 출력 해당 문제는 단순히 while문을 돌면서 올라간 높이를 계속 누적합하고, 이때의 높이가 V인지를 확인한 후에, 아니라면 B 만큼 빼주고, 하루를 더해주고,... 이런 방법으로는 변수에 해당하는 값을 시간내에 출력하지 못한다. 즉..