codeforces 507C
来源:互联网 发布:如何学习linux命令 编辑:程序博客网 时间:2024/05/17 09:01
满二叉树,可以递归求解
因为总是将一棵子树走完之后再到另外一棵
判断出口在左子树还是右子树,再加上走到这棵子树的步数。
#include <cstdio>#include <cstdlib>#include <cmath>#include <set>#include <stack>#include <vector>#include <sstream>#include <cstring>#include <string>#include <map>#include <windows.h>#include <queue>#include <algorithm>#include <iostream>#define FFI freopen("in.txt", "r", stdin)#define maxn 100010#define INF 0x3f3f3f3f#define inf 10000000#define MOD 1000000007#define ULL unsigned long long#define LL long long#define _setm(houge) memset(houge, INF, sizeof(houge))#define _setf(houge) memset(houge, -1, sizeof(houge))#define _clear(houge) memset(houge, 0, sizeof(houge))using namespace std;int h;LL n;int main() { while(scanf("%d%I64d", &h, &n) == 2) { LL ans = 0; while(h) { ++ans; LL x = 1LL << (h-1); if (n > x) { n -= x; ans += x * 2 - 1; } else { n = x - n + 1; } h --; } printf("%I64d\n", ans); } return 0;}
0 0
- Codeforces-507-C(c++)
- codeforces 507C
- Codeforces-340-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- CodeForces 156C Cipher
- codeforces 148 div2 C
- codeforces 242C
- Codeforces-234C Weather
- codeforces 106C Buns
- codeforces 158C
- Codeforces 243C
- CodeForces 13C Sequence
- Codeforces 13C Sequence
- 网页自适应+viewport介绍
- 第五题:Longest Palindromic Substring
- oracle权限问题
- poj 1463 Strategic game 树状dp
- 打开文件夹对话框用法
- codeforces 507C
- socket send 异常
- java之File对象对文件的操作常用的几个方法
- 在Tomcat上安装部署SAIKU
- iOS 图片显示原理
- 剖析 Linux hypervisor
- Codeforces 500C New Year Book Reading
- C和C++混合编程(error C2059: syntax error : 'string')
- sqlite3导入数据