# UVa 679 - Dropping Balls --- # 題目大意 有一深度為D的滿二元樹,依序丟球下去 每個節點都有一個標記,一開始是往左,當被經過時,就會換成右,再被經過一次,就切換成左,以此類推,直到最底層(葉節點) 輸出第I顆球最後會停在哪個節點 --- # 題解 I的二進位表示第I顆球"後"的狀態,因此看I-1的每一位決定往左還右 --- ```=C++ #include <bits/stdc++.h> #define ll long long #define pb push_back #define pf push_front #define ft first #define sec second #define pr pair<int,int> #define ISCC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; const ll MOD = 1e9+7; int t ,n ,m ,ok ,ans; string s; int main() { cin >> t; while(t--) { cin >> n >> m; ans = 1; m--; for(int i=0 ;i<n-1 ;i++ ,m >>= 1 ) ans = (m%2)?(ans<<1|1):(ans<<1); cout << ans << '\n'; } return 0; } ```