https://cn.vjudge.net/problem/UVA-679#author=0
二叉树第一题 上图上图 模拟来理解树的结构
#include<algorithm> #include<iostream> #include<vector> #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<ctime> #include<map> #include<stack> #include<set> #include<cstring> #include<sstream> using namespace std; typedef long long ll; const int maxn = 20; int s[maxn << maxn]; int main() { int D, I;//D深度 I小球个数 while (scanf("%d%d", &D, &I) == 2) { memset(s, 0, sizeof(s)); int k, n = (1 << D) - 1;//n是最大编号 for (int i = 0; i < I; i++) { k = 1; for (;;) { s[k] = 1 - s[k];//取反 k = s[k] ? 2 * k : 2 * k + 1;//相同状态则往左走 否则往右走 if (k > n) break; } } printf("%d\n", k / 2); } return 0; }
Comments | NOTHING