알고리즘

[알고리즘] 백준 21756 - 지우개 (C++)

blueberrysoda 2024. 11. 26. 23:43

[문제 링크] : https://www.acmicpc.net/problem/21756

#include <iostream>
#include <vector>
using namespace std;

int N;
vector<int> A, B;

int main(){
    cin >> N;
    for(int i=1; i<=N; i++){
        A.push_back(i);
    }

    while(A.size() != 1){
        B.clear();
        for(int i=1; i<A.size(); i+=2){
            B.push_back(A[i]);
        }
        A = B;
    }

    cout << A.front() << "\n";
    return 0;
}