전체 글
-
1021 - 회전하는 큐알고리즘 2023. 5. 26. 19:55
https://www.acmicpc.net/problem/1021 1021번: 회전하는 큐 첫째 줄에 큐의 크기 N과 뽑아내려고 하는 수의 개수 M이 주어진다. N은 50보다 작거나 같은 자연수이고, M은 N보다 작거나 같은 자연수이다. 둘째 줄에는 지민이가 뽑아내려고 하는 수의 위치가 www.acmicpc.net 문제요약 1. 첫 번째 원소를 뽑아낸다. 이 연산을 수행하면, 원래 큐의 원소가 a1, ..., ak이었던 것이 a2, ..., ak와 같이 된다. 2. 왼쪽으로 한 칸 이동. 이 연산을 수행하면, a1, ..., ak가 a2, ..., ak, a1이 된다. 3. 오른쪽으로 한 칸 이동. 이 연산을 수행하면, a1, ..., ak가 ak, a1, ..., ak-1이 된다. 2번 3번의 연산을 ..
-
1874 - 스택 수열알고리즘 2023. 5. 26. 19:39
https://www.acmicpc.net/problem/1874 1874번: 스택 수열 1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다. www.acmicpc.net 문제요약 첫 줄에 n (1 ≤ n ≤ 100,000) 둘째 줄부터 n개의 줄에는 수열을 이루는 1이상 n이하의 정수가 하나씩 순서대로 주어짐 8 7 6 5 4 3 2 1 --> 오름차순으로 빼주면서, stack에 쌓고( push ), "+" 둘째줄에 입력된 값이 stack 에 가장 위에 쌓이면, 출력( pop ), ..
-
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..
-
10828 - 스택카테고리 없음 2023. 5. 24. 22:23
https://www.acmicpc.net/problem/10828 import java.io.*; import java.util.Stack; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int row = Integer.parseInt(reader.readLine()); Stack stack = new Stack(); // 반복 for (int i = 0; i < row; i++) { String[] two = reader.readLine().split(" "); Str..
-
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..