UVA 679 Dropping Balls

1. 若当前结点球数为偶数, 左子树的总球数 = 右子树的总球数 = I / 2
2.若当前结点球数为奇数, 左子树的总球数 = 右子树的总球数 + 1 = (I + 1) / 2

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#define pi acos(-1.0)
#define LL long long
#define ULL unsigned long long
#define inf 0x3f3f3f3f
#define INF 1e18
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define debug(a) printf("---%d---\n", a)
#define mem0(a) memset(a, 0, sizeof(a))
#define memi(a) memset(a, inf, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
using namespace std;
typedef pair<int, int> P;
const double eps = 1e-10;
const int maxn = 1e6 + 5;
const int mod = 1e8;

int main(void)
{
//  freopen("C:\\Users\\wave\\Desktop\\NULL.exe\\NULL\\in.txt","r", stdin);
int T, D, I, k, i;
while (cin >> T && T >= 0){
while (T--){
cin >> D >> I;
k = 1;
for (i = 1; i <= D-1; i++){
if (I & 1) k *= 2;
else k = k * 2 + 1;
if (I & 1) I = (I + 1) / 2;
else I /= 2;
}
cout << k << endl;
}
}

return 0;
}

UVA - 679 Dropping Balls 规律

2015-05-10 23:54:07

UVa679 小球下落（树）

2016-03-17 10:49:08

UVA - 679 Dropping Balls

2014-08-14 15:22:35

UVA 679 - Dropping Balls

2015-07-28 14:35:24

UVA 679 Dropping Balls

2016-10-10 14:44:27

uva 679 - Dropping Balls

2013-06-11 17:21:13

Uva - 679 - Dropping Balls

2015-06-15 18:36:56

Dropping Balls UVA - 679

2017-04-17 10:40:34

UVA - 679 - Dropping Balls

2018-04-11 23:49:28

UVa 679 Dropping Balls

2014-08-06 14:51:17

不良信息举报

UVA 679 Dropping Balls