Skip to content

Commit 9ce5f2b

Browse files
committed
[Bronze II] Title: 지우개, Time: 104 ms, Memory: 14236 KB, Score: 100 point -BaekjoonHub
1 parent 2996dea commit 9ce5f2b

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# [Bronze II] 지우개 - 21756
2+
3+
[문제 링크](https://www.acmicpc.net/problem/21756)
4+
5+
### 성능 요약
6+
7+
메모리: 14236 KB, 시간: 104 ms
8+
9+
### 분류
10+
11+
구현, 수학, 시뮬레이션
12+
13+
### 제출 일자
14+
15+
2025년 5월 8일 16:57:49
16+
17+
### 문제 설명
18+
19+
<p><mjx-container class="MathJax" jax="CHTML" style="font-size: 109%; position: relative;"> <mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D441 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>N</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$N$</span></mjx-container>개의 칸에 <mjx-container class="MathJax" jax="CHTML" style="font-size: 109%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mn class="mjx-n"><mjx-c class="mjx-c31"></mjx-c></mjx-mn></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mn>1</mn></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$1$</span></mjx-container> 부터 <mjx-container class="MathJax" jax="CHTML" style="font-size: 109%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D441 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>N</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$N$</span></mjx-container> 까지의 수들이 왼쪽부터 순서대로 저장되어 있다. 또, 각 칸은 왼쪽부터 <mjx-container class="MathJax" jax="CHTML" style="font-size: 109%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mn class="mjx-n"><mjx-c class="mjx-c31"></mjx-c></mjx-mn></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mn>1</mn></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$1$</span></mjx-container> 부터 <mjx-container class="MathJax" jax="CHTML" style="font-size: 109%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D441 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>N</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$N$</span></mjx-container>까지 순서대로 번호가 붙어 있다. 즉, 처음에는 각 칸의 번호와 각 칸에 저장된 수가 같다.</p>
20+
21+
<p>아래 그림은 <mjx-container class="MathJax" jax="CHTML" style="font-size: 109%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D441 TEX-I"></mjx-c></mjx-mi><mjx-mo class="mjx-n" space="4"><mjx-c class="mjx-c3D"></mjx-c></mjx-mo><mjx-mn class="mjx-n" space="4"><mjx-c class="mjx-c37"></mjx-c></mjx-mn></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>N</mi><mo>=</mo><mn>7</mn></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$N = 7$</span></mjx-container>일 때의 예이다.</p>
22+
23+
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/1587dd00-130c-42a0-af6e-68b3b484a1b8/-/preview/" style="width: 361px; height: 90px;"></p>
24+
25+
<p>다음 작업을 수가 정확히 하나가 남을 때 까지 반복한다.</p>
26+
27+
<p>(A) 홀수번 칸의 수들을 모두 지운다 (B) 남은 수들을 왼쪽으로 모은다.</p>
28+
29+
<p>제일 첫 작업의 (A) 단계가 끝나면 칸들의 상태는 다음과 같을 것이다.</p>
30+
31+
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/1bedbcf7-ee56-4bb0-a83b-d6abbb34ae46/-/preview/" style="width: 361px; height: 90px;"></p>
32+
33+
<p>(B) 단계가 끝나면 다음과 같을 것이다.</p>
34+
35+
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/7f311585-5dd0-4033-ada3-5fb9aa0df18b/-/preview/" style="width: 361px; height: 90px;"></p>
36+
37+
<p>두번째 작업이 진행되면 칸들은 아래 두 그림과 같이 바뀔 것이다.</p>
38+
39+
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/e070dc76-59fc-4fa6-a0b3-bf310f78dccd/-/preview/" style="width: 361px; height: 90px;"></p>
40+
41+
<p style="text-align: center;"><img alt="" src="https://upload.acmicpc.net/e7c0cbf8-ab7d-4b7c-bdac-28b433c83c95/-/preview/" style="width: 361px; height: 90px;"></p>
42+
43+
<p>이제 수가 하나 남았으므로 작업은 더 이상 진행되지 않는다.</p>
44+
45+
<p><mjx-container class="MathJax" jax="CHTML" style="font-size: 109%; position: relative;"> <mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D441 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>N</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$N$</span></mjx-container>을 입력으로 받아 위와 같이 작업을 진행했을 때 마지막으로 남는 수를 계산하는 프로그램을 작성하라.</p>
46+
47+
### 입력
48+
49+
<p>첫 번째 줄에 정수 <mjx-container class="MathJax" jax="CHTML" style="font-size: 109%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-mi class="mjx-i"><mjx-c class="mjx-c1D441 TEX-I"></mjx-c></mjx-mi></mjx-math><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>N</mi></math></mjx-assistive-mml><span aria-hidden="true" class="no-mathjax mjx-copytext">$N$</span></mjx-container>이 주어진다.</p>
50+
51+
### 출력
52+
53+
<p>마지막으로 남는 수를 한 줄에 출력한다.</p>
54+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main{
5+
6+
static int n;
7+
static Queue<Integer> numbers;
8+
public static void main(String[] args) throws Exception{
9+
inputSetting();
10+
11+
int now;
12+
while(1 < n){
13+
for(int i = 0; i < n; i++){
14+
now = numbers.poll();
15+
if((i + 1) % 2 == 1) continue;
16+
17+
numbers.add(now);
18+
}
19+
n = numbers.size();
20+
}
21+
System.out.println(numbers.poll());
22+
}
23+
24+
static void inputSetting() throws Exception{
25+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
26+
27+
numbers = new ArrayDeque<>();
28+
n = Integer.parseInt(br.readLine());
29+
30+
for(int i = 1; i < n + 1; i++) numbers.add(i);
31+
}
32+
}

0 commit comments

Comments
 (0)