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. mysql自连接

    自连接: -- 求7369员工编号,姓名,经理编号和经理姓名 select e1.empno,e1.ename,e2.empno,e2.ename from emp e1,emp e2 where e ...

  2. Java 加密PDF设置密码并添加水印

    /** * Project Name:XXX * File Name:EncryptLogFile.java * Date:2016-6-12上午11:56:38 * Copyright (c) 20 ...

  3. LeetCode6.Z字形变换 JavaScript

    将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下: L C I R E T ...

  4. java 后台返回文件流到浏览器

    package com.springbootblog.controller; import io.swagger.annotations.ApiImplicitParam;import io.swag ...

  5. 原生js方面的兼容性问题

    1.关于获取行外样式 currentStyle 和 getComputedStyle 出现的兼容性问题  我们都知道js通过style不可以获取行外样式,当我们需要获取行外样式时:  我们一般通过这两 ...

  6. Xadmin使用二

    1:修改site-title和site-footer,增加菜单折叠效果 在adminx.py中增加下面代码: class GlobalSetting(object): # 设置Title site_t ...

  7. HTTP状态保持的原理

    a)在用户登录之后,浏览器返回响应的时候会在响应中添加上cookieb)浏览器接收到cookie之后会自动保存c)当用户再次请求同一服务器中的其他网页的时候,浏览器会自动带上之前保存的cookied) ...

  8. Flask中异常捕获

    HTTP 异常主动抛出 abort 方法 抛出一个给定状态代码的 HTTPException 或者 指定响应,例如想要用一个页面未找到异常来终止请求,你可以调用 abort(404). 参数: cod ...

  9. Laravel系列之CMS系统学习 — 角色、权限配置【2】

    一.RBAC分析 基于角色的权限访问控制(Role-Based Access Control),这里存在这么几个玩意儿:角色.权限,用户 表:roles.permissions.role_has_pe ...

  10. centos编译安装rabbitmq

    安装环境 [root@VM_12_50_centos rabbitmq]# uname -a Linux VM_12_50_centos 3.10.0-514.21.1.el7.x86_64 #1 S ...