백준의 카드2(2164) 문제이다.

[ 문제 바로가기 ]


[ 문제풀이 ]

1) 이 문제는 카드1 문제와 거의 똑같은 문제이다. 오히려, 카드1이 처리해줘야 할 것이 하나 더 있는 셈이다.

   이 문제에 대한 자세한 풀이는 카드1 을 참고하도록 하자. 또한, 카드 1을 풀어보지 않았다면, 이 문제를 풀고 꼭 풀어보자.

   [ 카드1 문제 바로가기(Click) ]

   [ 카드1 문제풀이 바로가기(Click) ]


[ 소스코드 ]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
#include<queue>
 
#define endl "\n"
using namespace std;
 
int N;
queue<int> Q;
 
void Input()
{
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        Q.push(i);
    }
 
    if (Q.size() == 1)
    {
        cout << 1 << endl;
        exit(0);
    }
}
 
void Solution()
{
    int Remainder;
    while (1)
    {
        Q.pop();
        if (Q.size() == 1)
        {
            Remainder = Q.front();
            break;
        }
        
        Q.push(Q.front());
        Q.pop();
    }
 
    cout << Remainder << endl;
}
 
void Solve()
{
    Input();
    Solution();
}
 
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    //freopen("Input.txt", "r", stdin);
    Solve();
 
    return 0;
}
cs

+ Recent posts