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,赢的人可以将 ...
随机推荐
- java常见验证邮箱、电话号码、日期等格式
package besttone.utils; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * 90%的验证 ...
- SpringBoot非官方教程 | 第二篇:Spring Boot配置文件详解
转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot2-config-file/ 本文出自方志朋的博客 ...
- ATK系列库说明
初衷 重构和复用是软件的一个古老话题. 在日常的软件项目开发的过程序中,如何保证团队代码的强健,同时在不断变化的需过程中最大限度的保障代码的一致性,是项目开发中的难以控制的,我们可以借助各种源码管理和 ...
- Oracle oerr工具介绍
(1)什么是oerr oerr是Oracle提供的在UNIX/Linux上查看Oracle错误的小工具,使用起来非常方便. (2)如何使用 oerr工具位于ORACLE_HOME下面,可以使用whic ...
- html5语义化标签——回顾
html5 头部结构 <!doctype html> <meta charset=“utf-8”/> <header></header> 页眉 ...
- 安装sass遇到的坑
一.安装Sass https://www.sass.hk/install/ 根据网站的步骤进行安装 Ruby版本的选择 我第一次下载是在Ruby官网上下的2.5.0版本得ruby.然而下载了之后无(不 ...
- 困扰我的c++语法
以下是我上周学习c++ primer的心得: 1 数组引用作为形参 c++允许将变量定义成数组的引用,以下列代码为例.形参为int (&arr)[10],该参数需分成两部分说明,引用名和 引用 ...
- ABAP术语-Error Message
Error Message 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/30/1058283.html Information from ...
- npm cnpm npx nvm 傻傻分不清
用过 npm cnpm吗?知道 npx nvm 吗? 唔~ npm npm 的全称是 Node Package Manager 是 JavaScript 世界的包管理工具,并且是 Node.js 平台 ...
- 二、html篇
1.<br/> 有时css实现换行比较麻烦,可以使用该标签进行换行. 2.<strong></strong> <ins></ins> & ...