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

 

Sample Output 1


There are 4 patties in the bottom-most 7 layers of a level-2 burger (BBPPPBPBPPPBB).


Sample Input 2

 

Sample Output 2


The bottom-most layer of a level-1 burger is a bun.


Sample Input 3

 

Sample Output 3


A level-50 burger is rather thick, to the extent that the number of its layers does not fit into a 32-bit integer.

分析:

比较好玩的一个题目,给你一种关于汉堡的排序方法,然后顺着吃X个问能吃多少个面包,首先看到比较大的数先算了一下会不会爆long long,发现不会之后直接写递归,写完样例没过,检查了半天又把吃一个N等级的所有的个数用一个数组进行存储,中间换了一种形式实现,又找到了一个bug(脑残少算了一个-1),最后AC了。

AC代码:

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std; ll length[];
ll sum0[];
ll sum = ;
ll f(ll n,ll x0){
if(n == ){
if(x0 == ){
return ;
}else if(x0 == ){
return ;
}else if(x0 == ){
return ;
}else if(x0 == ){
return ;
}else if(x0 == ){
return ;
}
}
if(x0 == ){
return ;
}else if(x0 == length[n]){
return sum0[n];
}if(x0 == ((length[n]+)>>)){
return sum0[n-]+;
}else if(x0 < ((length[n]+)>>)){
return f(n-,x0-);
}else{
return f(n-,(x0-length[n-]-))+sum0[n-]+;
}
} int main() {
length[] = ;
sum0[] = ;
for(ll i = ; i <= ; i ++){
length[i] = (length[i-] * ) + ;
sum0[i] = sum0[i-]*+;
}
//pld(sum0[50]); pn
ll n,x;
sld(n) sld(x);
pld(f(n,x)); pn
return ;
}
//10 11 12 14 15

Atcoder Beginner Contest 115 D Christmas 模拟,递归 B的更多相关文章

  1. AtCoder Beginner Contest 115 题解

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

  2. AtCoder Beginner Contest 115 Solution

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

  3. AtCoder Beginner Contest 148 题解

    目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...

  4. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  5. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  6. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  7. AtCoder Beginner Contest 161

    比赛链接:https://atcoder.jp/contests/abc161/tasks AtCoder Beginner Contest 161 第一次打AtCoder的比赛,因为是日本的网站终于 ...

  8. AtCoder Beginner Contest 223

    AtCoder Beginner Contest 223 A是纯纯的水题,就不说了 B - String Shifting 思路分析 我真的sb,一开始想了好久是不是和全排列有关,然后读了好几遍题目也 ...

  9. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

随机推荐

  1. docker的安装和简单配置

    docker的安装和简单配置 docker是balabalabala...懒得介绍. 国内安装docker很蛋疼,按照官方配置好了软件源之后,几十MB的安装文件下载要半天,没办法,docker默认的软 ...

  2. 函数function

    function add(x,y,z){ sum = x + y +z; document.write(x+"+"+y+"+"+z+"="+ ...

  3. ArcGIS 要素类平移工具-arcgis案例实习教程

    ArcGIS 要素类平移工具-arcgis案例实习教程 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:对整个要素类,按指定偏移距离,进行整体平移. 优点:使用 ...

  4. linux下nginx日常操作

    一.检查配置文件语法 [root@node2 /]# nginx -tc /usr/local/nginx/conf/nginx.conf nginx: the configuration file ...

  5. 移动端与web端的测试点的差别

    单纯从功能测试的层面上来讲的话,APP 测试.web 测试 在流程和功能测试上是没有区别的.根据两者载体不一样,则区别如下:系统结构方面web项目,b/s架构,基于浏览器的:web测试只要更新了服务器 ...

  6. openal在vs2010中的配置

    下载openal开发工具:相关资料可以在OpenAL官网http://connect.creativelabs.com/openal/default.aspx上获得.这里下载的SDK为OpenAL11 ...

  7. python中的集合

    在python中,普通集合是可变数据类型 通过以下案例说明: >>> s = {1, 2, 3, 4} >>> id(s) 2108634636808 >&g ...

  8. jquery-confirm使用方法

    简要教程 jquery-confirm是一款功能强大的jQuery对话框和确认框插件.它提供多种内置的主题效果,可以实现ajax远程加载内容,提供动画效果和丰富的配置参数等.它的特点还有: 可以使用键 ...

  9. Spring MVC相关

    配置文件说明 web.xml, spring配置文件 applicationContext.xml, spring配置文件, mybatis连接mysql配置文件 sql-map-config-mys ...

  10. python_字符编码

    一 了解字符编码的知识储备 1.计算机基础知识 2.电脑存放组成: 硬盘 - 内存 -(二级缓存.一级缓存.cpu寄存器)- cpu # cpu交互的是用户能识别的数据:字符# 硬盘中最终存储的数据: ...