Atcoder Beginner Contest 115 D Christmas 模拟,递归 B
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的更多相关文章
- 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 ...
- AtCoder Beginner Contest 148 题解
目录 AtCoder Beginner Contest 148 题解 前言 A - Round One 题意 做法 程序 B - Strings with the Same Length 题意 做法 ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- AtCoder Beginner Contest 161
比赛链接:https://atcoder.jp/contests/abc161/tasks AtCoder Beginner Contest 161 第一次打AtCoder的比赛,因为是日本的网站终于 ...
- AtCoder Beginner Contest 223
AtCoder Beginner Contest 223 A是纯纯的水题,就不说了 B - String Shifting 思路分析 我真的sb,一开始想了好久是不是和全排列有关,然后读了好几遍题目也 ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
随机推荐
- ToroiseSVN和VisualSVN-server的配置使用, 外网访问SVN 版本库
https://www.cnblogs.com/Leo_wl/p/3475167.html
- SnowFlake学习
分布式系统中生成全局唯一且趋势递增ID UUID - 太长,无序,数据库插入分裂性能不行 利用数据库自增序列,等步长生成 - 依赖数据库 SnowFlake:使用见下图 抄代码 https://www ...
- Unity添加多个可视镜头Preview功能(二)
制作好并摆放好镜头以后,在Preview.cs里添加一个time单个镜头移动时间的变量,并在PreviewEditor下绘制在Inspector面板下. 然后,添加一个FollowPreviewPat ...
- 2017-11-11 Sa Oct How to open a browser in Python
2017-11-11 Sa Oct How to open a browser in Python python -m webbrowser "http://www.example.com/ ...
- std::condition_variable::wait_until segment
原因是使用了 -static 改为 -static-libstdc++ -static-libgcc
- Xamarin.Form怎么调用原生方法
---恢复内容开始--- Xamarin.Form怎么调用原生包 今天我想和大家分享的是有关Xamarin如何调用安卓的原生代码,下面的例子以大家可能会经常用到的微信WX方法的调用. 首先我们新建一个 ...
- 3D Math Keynote 2
[3D Math Keynote 2] 1.方向(diretion),指的是前方朝向.方位(orientation),指的是head.pitch.roll. 2.欧拉角的缺点: 1)给定方位的表达式不 ...
- scrapy 的log功能
只需要在配置文件 setting.py文件中加入LOG_FILE = "mySpider.log"LOG_LEVEL = "INFO" Scrapy提供5层lo ...
- 刷题的model格式(请用英文)
[抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: [英文数据结构或算法,为什么不用别的数据 ...
- [leetcode]272. Closest Binary Search Tree Value II二叉搜索树中最近的值2
Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...