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 ...
随机推荐
- socket.io诡异的问题
在socket.io客户端连接的时候,如果传入的query包含“sid”这个键时会报错,不知道具体原因.
- spark报错:warn util.utils::service 'sparkUI' can not bind on part 4040.Attempting port 4041.
转载自:https://blog.csdn.net/weixin_41629917/article/details/83190258
- MYSQL5.7脚本运行时出现[Warning] Using a password on the command line interface can be insecure
MYSQL版本:5.7 在写linux脚本执行MYSQL命令的时候,如果使用 MYSQL="mysql -hlocalhost -P3306 -uroot -p666666" 登陆 ...
- WPF 学习笔记
依赖属性(Dependency Property) 相比较于普通属性,依赖属性有以下特点: 变化通知(change notification) 节省内存 使用某种带优先级决定策略(resolution ...
- [原创] debian 9.3 搭建Jira+Confluence+Bitbucket项目管理工具(二) -- 安装jira 7.5.4
[原创] debian 9.3 搭建Jira+Confluence+Bitbucket项目管理工具(二) -- 安装jira 7.5.4 环境都配置好以后, 开始搭建Jira的环境, 这里参考了一篇文 ...
- java命令--jstat 工具使用
jstat(JVM Statistics Monitoring Tool)是用于监控虚拟机各种运行状态信息的命令行工具.他可以显示本地或远程虚拟机进程中的类装载.内存.垃圾收集.JIT编译等运行数据, ...
- Ubuntu上部署Jenkins
1.Ubuntu上安装jdk.tomcat https://blog.csdn.net/evankaka/article/details/50463782 2.Ubuntu上配置Jenkins htt ...
- Spring MVC相关
配置文件说明 web.xml, spring配置文件 applicationContext.xml, spring配置文件, mybatis连接mysql配置文件 sql-map-config-mys ...
- Codeforces Round #553 (Div. 2) A题
题目网址:http://codeforces.com/contest/1151/problem/A 题目大意:给定一个由大写字母构成的字符串和它的长度,有这样的操作,使任意一个字母变成与其相邻的字母, ...
- 基于IPv6的数据包抓包分析(GNS3)
一.实验拓扑 二.路由配置 路由R1.R2.R3.R4.R5详细配置: 1.配置R1: R1(config)#interface fastEthernet 0/1 R1(config-if)#ipv6 ...