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,赢的人可以将 ...
随机推荐
- jstl 中substring,length等函数用法
引入jstl库:<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%& ...
- sql树形查询
sql: 使用Common As:递归公用表 https://docs.microsoft.com/en-us/sql/t-sql/queries/with-common-table-expressi ...
- Struts2后期(这框架目前正处于淘汰状态)
Struts2第三天 课程回顾:Struts2框架的第二天 1. Servlet的API * ActionContext对象 * ServletActionContext对象 2. 结构类型的跳转 * ...
- c# Hash一致算法实现负载均衡
开篇吹牛..... 不吹了,因为我不擅长算法,就不胡说八道了. 现在一般的实现负载均衡,主要采用2种方法: 1.轮训 2.负载均衡算法 轮训就不说了,负载均衡现在一般采用HASH一致算法 不多说 ...
- Linux下文件字符编码格式检测和转换
目前多数情况下, 我们遇到的非英文字符文件都是使用UTF-8编码的, 这时一般我们查看这些文件的内容都不会有问题. 不过有时, 我们有可能会遇到非UTF-8编码的文件, 比如中文的GBK编码, 或者俄 ...
- vue.js 组件-全局组件和局部组件
这两天学习了Vue.js 感觉组件这个地方知识点挺多的,而且很重要,所以,今天添加一点小笔记. 首先Vue组件的使用有3个步骤,创建组件构造器,注册组件,使用组件3个方面. 代码演示如下: <! ...
- flask的模板
flask用的是jinja2的模板 模板其实是一个包含响应文本的文件,其中用占位符(变量)表示动态部分,告诉模板引擎其具体的值需要从使用的数据中获取 使用真实值替换变量,再返回最终得到的字符串,这个过 ...
- windows环境下安装scrapy框架报错问题--最快捷有效的解决方案
windows在执行如下命令,安装scrapy的过程中会报错: pip install scrapy 报错分析: windows环境下,会出现如下错误: 1.提示的错误是编译环境的问题,字面意思看需要 ...
- UVA 1593 Alignment of Code(紫书习题5-1 字符串流)
You are working in a team that writes Incredibly Customizable Programming Codewriter (ICPC) which is ...
- ABAP CDS ON HANA-(11)ABAP CDSでの関連付け
Association in ABAP CDS An association in CDS view joins different data sources. Defining and using ...