C++ 基礎題 a249: Dropping Balls

依題目用模擬即可,以下為程式碼

#include<bits/stdc++.h>
using namespace std;

bitset<2500> tree;

int main(){
    ios::sync_with_stdio(false);cin.tie(0);

    int iptNum;
    cin>>iptNum;
    while(iptNum--){
        int d,n;
        tree.set();
        cin>>d>>n;

        int pos;
        for(int i=0;i<n;i++){
            pos=1;
            for(int j=1;j<d;j++){
                if(tree[pos]){
                    tree[pos]=false;
                    pos*=2;
                }else{
                    tree[pos]=true;
                    pos=pos*2+1;
                }
            }
        }
        cout<<pos<<"\n";
    }
    return 0;
}

發佈留言