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 ...
随机推荐
- zabbix添加自定义监控项目
在zabbix里添加一个自定义监控项目,简单做个笔记,怕忘了 首先需要定义 zabbix_agentd.conf 中的 UnsafeUserParameters 修改为 UnsafeUserPara ...
- echart 分组属性
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- LevelDB源码分析-Open
Open LevelDB的初始化主要由Open函数实现: Status DB::Open(const Options &options, const std::string &dbna ...
- React Native: unable to load scripts from assets 'index.android.bundle' on real device
问题:重新建了一个项目后,运行react-native run-android报: unable to load scripts from assets 'index.android.bundle' ...
- pop() 删除掉数组的最后一个元素
下面的代码首先创建了一个拥有四个元素的数组 myFish,然后删除掉它的最后一个元素. let myFish = ["angel", "clown", &quo ...
- java命令--jstat 工具使用
jstat(JVM Statistics Monitoring Tool)是用于监控虚拟机各种运行状态信息的命令行工具.他可以显示本地或远程虚拟机进程中的类装载.内存.垃圾收集.JIT编译等运行数据, ...
- Go语言编程读书笔记:Go channel(1)
Channel是Go语言在语言级别提供的goroutine间的通信方式.我们可以用channel在两个或多个goroutine之间传递消息.channel是进程内的通信方式,因此通过channel传递 ...
- C# 截取两个指定字符串中间的字符串列表
/// <summary> /// 截取两个指定字符串中间的字符串列表(开始和结束两个字符串不能相同!) /// </summary> /// <param name=& ...
- java中LIst转换成Json
List转换成json串 public String getNameListByID(Long Id) { List<Name> nameLists= nameService.select ...
- C# DataTable抽取Distinct数据(不重复数据)[z]
DataTable dataTable; DataView dataView = dataTable.DefaultView; DataTable dataTableDisti ...