AcCoder Contest-115 D - Christmas
D - Christmas
Time limit : 2sec / Memory limit : 1024MB
Score : 400 points
Problem Statement
In some other world, today is Christmas.
Mr. Takaha decides to make a multi-dimensional burger in his party. A level-L burger (L is an integer greater than or equal to 0) is the following thing:
- A level-0 burger is a patty.
- A level-L burger (L≥1) is a bun, a level-(L−1) burger, a patty, another level-(L−1) burger and another bun, stacked vertically in this order from the bottom.
For example, a level-1 burger and a level-2 burger look like BPPPB
and BBPPPBPBPPPBB
(rotated 90 degrees), where B
and P
stands for a bun and a patty.
The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
Constraints
- 1≤N≤50
- 1≤X≤( the total number of layers in a level-N burger )
- N and X are integers.
Input
Input is given from Standard Input in the following format:
N X
Output
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger.
Sample Input 1
2 7
Sample Output 1
4
There are 4 patties in the bottom-most 7 layers of a level-2 burger (BBPPPBPBPPPBB
).
Sample Input 2
1 1
Sample Output 2
0
The bottom-most layer of a level-1 burger is a bun.
Sample Input 3
50 4321098765432109
Sample Output 3
2160549382716056
A level-50 burger is rather thick, to the extent that the number of its layers does not fit into a 32-bit integer.
题意: 一个L级别的汉堡由 一个b ,一个L-1级别的汉堡, 一个p, 一个L-1级别的汉堡, 一个b 共五层组成。
0 级别的汉堡单独由 p 组成。
例如 1级别的汉堡由 b, 1-1, p, 1-1, b 也就是bpppb
2级别的汉堡由 b, 2-1, p, 2-1, b 组成 也就是b(bpppb)p(bpppb)b
问: 现在有一个N级别的汉堡,从最底层(最顶层)开始吃 吃掉x层后,一共吃掉了多少层p
#include<cstdio>
#include<algorithm>
using namespace std; long long arr[];
long long stu[];
long long ans = ;
int n;
long long x;
void f(int d){
if(x==arr[d]){//如果吃x层会整好吃完级别为 d 的汉堡
ans += stu[d];
return ;
}else if(x){
x--;// 吃掉最底层的 b
if(x>arr[d-]){// x 落在了上面的 L-1 级的汉堡
x-=arr[d-];//吃掉下面的 L-1 级的汉堡
ans += stu[d-];// L-1级别的汉堡有stu[l-1]层 p
x--;// 吃掉中间的 p
ans++;
if(x)f(d-);// 进入上面的 L-1 级的汉堡
//这里可以不进行if判断直接进入 因为进入后还会判断x非零
} else f(d-);// 落点在下面的 L-1 级汉堡
}
}
int main(){
arr[] = ;
arr[] = ;
arr[] = ;
stu[] = ;
stu[] = ;
stu[] = ;
for(int i=;i<;i++){
//arr[i] = 1+arr[i-1]+1+arr[i-1]+1;
arr[i] = arr[i-]*+;// 级别为 i 的汉堡的层数 b+p
stu[i] = stu[i-]*+;// 级别为 i 的汉堡的 p 的数量
}
scanf("%d%lld",&n,&x);
f(n);
printf("%lld\n",ans);
return ;
}
AcCoder Contest-115 D - Christmas的更多相关文章
- Atcoder Beginner Contest 115 D Christmas 模拟,递归 B
D - Christmas Time limit : 2sec / Memory limit : 1024MB Score : 400 points Problem Statement In some ...
- AtCoder Beginner Contest 115 题解
题目链接:https://abc115.contest.atcoder.jp/ A Christmas Eve Eve Eve 题目: Time limit : 2sec / Memory limit ...
- AtCoder Beginner Contest 115 Solution
A Christmas Eve Eve Eve Solved. #include <bits/stdc++.h> using namespace std; int main() { int ...
- weekly contest 115
958. Check Completeness of a Binary Tree Given a binary tree, determine if it is a complete binary t ...
- 【Leetcode周赛】从contest-111开始。(一般是10个contest写一篇文章)
Contest 111 (题号941-944)(2019年1月19日,补充题解,主要是943题) 链接:https://leetcode.com/contest/weekly-contest-111 ...
- 江西财经大学第一届程序设计竞赛 G题 小Q的口袋校园
链接:https://www.nowcoder.com/acm/contest/115/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...
- 江西财经大学第一届程序设计竞赛 F题 解方程
链接:https://www.nowcoder.com/acm/contest/115/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...
- 江西财经大学第一届程序设计竞赛 H题 求大数的阶乘
链接:https://www.nowcoder.com/acm/contest/115/H 来源:牛客网 晚上,小P喜欢在寝室里一个个静静的学习或者思考,享受自由自在的单身生活. 他总是能从所学的知识 ...
- HZNU_TI1050 训练实录
菜鸡队训练实录 比赛记录:[名称:奖项 / 排名] 2018: ZJPSC Bronze / 86 CCPC Jilin ...
- 江西财经大学第一届程序设计竞赛 I
链接:https://www.nowcoder.com/acm/contest/115/I来源:牛客网 题目描述 小P和小Q是好朋友,今天他们一起玩一个有趣的游戏. 他们的初始积分都为1,赢的人可以将 ...
随机推荐
- 初学bind
其实项目中还没有用到. 但自己还是想逐步了解一些高级的JS语法,不是为了炫技,也不像找前端的工作. 主要目的是:1.学习设计思想,提升解决问题的能力2.让自己的脑子动起来,别太笨. 简单的几句话总结一 ...
- Win7下运行VC程序UAC权限问题 VC2010设置UAC权限方法
https://msdn.microsoft.com/en-us/library/bb756929.aspx 我使用的是VS2010,设为连接器清单文件的uac执行级别 直接项目右键---属性---配 ...
- 如何打卡后缀为3ds的文件
打开.3DS文件 3DS文件怎么打开? 用它吧:a3dsviewer,顾名思义,一个3D文件浏览工具,为用户提供一个快速和简单的3DS文件浏览器很容易. 这里是一些主要特点的“a3dsviewer”: ...
- 01_常用 Linux 命令的基本使用
01. 学习 Linux 终端命令的原因 Linux 刚面世时并没有图形界面,所有的操作全靠命令完成,如 磁盘操作.文件存取.目录操作.进程管理.文件权限 设定等 在职场中,大量的 服务器维护工作 都 ...
- [Windows]ping itsafe&环境变量
(1)when you ping a computer from itsafe,the ping command should return the local IP address. (2)wind ...
- oracle中特殊字符替换
replace语法: REPLACE(char,search_string,[replacement_string]) 在replace中,每个search_String 都会被replacement ...
- SmallMQ发布
最近一直学习,主要处理java的分布式,MQ,RPC,通信,数据库,缓存等方向. 一般现在的MQ都是企业级的,庞大,功能齐全.最主要是代码量大,对于我们这些小程序员而言,太大,修改困难,修复更加困难, ...
- c c++面试c工程开发之宏定义和条件编译
多数c语言的初学者对c工程开发过程各个阶段的作用理解不到位,而这方面的的知识又是实际开发过程中经常用到的技能点,所以就成为面试考察中一个重要的考察方面.例如:头文件的作用.头文件的内容:链接的作用和意 ...
- Linux的开山篇
一.Linux的学习方向 1.2Linux运维工程师 1.2.2Linux嵌入式开发工程师 1.2.3在Linux下做各种程序开发 javaEE 大数据 Python PHP C/ ...
- 通过Ops Manager安装管理mongodb-3.4集群
node1 Ops Manager,mongodb,agent node2 mongodb,agent node3 mongodb,agent 参考文档 https://docs.opsmanager ...