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的更多相关文章

  1. Atcoder Beginner Contest 115 D Christmas 模拟,递归 B

    D - Christmas Time limit : 2sec / Memory limit : 1024MB Score : 400 points Problem Statement In some ...

  2. AtCoder Beginner Contest 115 题解

    题目链接:https://abc115.contest.atcoder.jp/ A Christmas Eve Eve Eve 题目: Time limit : 2sec / Memory limit ...

  3. AtCoder Beginner Contest 115 Solution

    A Christmas Eve Eve Eve Solved. #include <bits/stdc++.h> using namespace std; int main() { int ...

  4. weekly contest 115

    958. Check Completeness of a Binary Tree Given a binary tree, determine if it is a complete binary t ...

  5. 【Leetcode周赛】从contest-111开始。(一般是10个contest写一篇文章)

    Contest 111 (题号941-944)(2019年1月19日,补充题解,主要是943题) 链接:https://leetcode.com/contest/weekly-contest-111 ...

  6. 江西财经大学第一届程序设计竞赛 G题 小Q的口袋校园

    链接:https://www.nowcoder.com/acm/contest/115/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  7. 江西财经大学第一届程序设计竞赛 F题 解方程

    链接:https://www.nowcoder.com/acm/contest/115/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  8. 江西财经大学第一届程序设计竞赛 H题 求大数的阶乘

    链接:https://www.nowcoder.com/acm/contest/115/H 来源:牛客网 晚上,小P喜欢在寝室里一个个静静的学习或者思考,享受自由自在的单身生活. 他总是能从所学的知识 ...

  9. HZNU_TI1050 训练实录

    菜鸡队训练实录 比赛记录:[名称:奖项 / 排名] 2018: ZJPSC                       Bronze      / 86 CCPC Jilin              ...

  10. 江西财经大学第一届程序设计竞赛 I

    链接:https://www.nowcoder.com/acm/contest/115/I来源:牛客网 题目描述 小P和小Q是好朋友,今天他们一起玩一个有趣的游戏. 他们的初始积分都为1,赢的人可以将 ...

随机推荐

  1. Android学习笔记_10_ContentProvider内容提供者的使用

    一.使用ContentProvider共享数据 当应用继承ContentProvider类,并重写该类用于提供数据和存储数据的方法,就可以向其他应用共享其数据.以前我们学习过文件的操作模式,通过指定文 ...

  2. CSU 1023 修路(二分+模拟)

    前段时间,某省发生干旱,B山区的居民缺乏生活用水,现在需要从A城市修一条通往B山区的路.假设有A城市通往B山区的路由m条连续的路段组成,现在将这m条路段承包给n个工程队(n ≤ m ≤ 300).为了 ...

  3. 中小学信息学奥林匹克竞赛-理论知识考点--IP地址

    IP地址同身份证号一样,具有唯一性! 每个人都有一个唯一的标识:身份证号. 互联网中的计算机也一样,具有一个唯一的标识:IP地址. IP地址是一个32位的二进制数,通常被分割为4个“8位二进制数”(也 ...

  4. 初入AngularJS基础门

    作为mvvm 框架过重 不适用于性能比较高的移动端的web栈, ui组建性对复杂,不利于重用 AngularJS 构建一个CRUD ( create retrieve update delete )的 ...

  5. html、css和js原生写一个模态弹出框,顺便解决父元素半透明子元素不透明效果

    模态框: html部分: <!-- 按钮 --> <button id="box" onclick="pop_box()">弹出框< ...

  6. Python学习之路——文件操作

    文件操作分三步:打开文件,读写文件,关闭文件.读取操作时没有给read函数加括号,会出现下面这样的车祸 >>> data = open('/home/supersun/Documen ...

  7. Oracle数据库中游标的游标的使用

    本人不喜欢说概念啥的,就直接说明使用方法吧 案例1: DECALRE --声明游标 CURSOR C_USER(C_ID NUMBER) IS SELECT NAME FROM USER WHERE ...

  8. getElementsByName和getElementById

    1: 今天分享工作中遇到的一个小细节 1.1 先介绍一下两个方法分别是: 1.2 getElementById()  :可返回对拥有指定 ID 的第一个对象的引用,如果您需要查找文档中的一个特定的元素 ...

  9. 通过匿名管道获取CMD运行结果

    #include <iostream> #include <string> #include <Windows.h> using namespace std; /* ...

  10. ABAP术语-ABAP Workbench

    ABAP Workbench 原文:http://www.cnblogs.com/qiangsheng/archive/2007/12/10/989037.html Integrated graphi ...