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 ...
随机推荐
- 两将军问题、拜占庭将军问题、TCP三路握手过程的联系
2015年初时产生了一个疑问:基于不可靠的通信链路,为什么在两将军问题中永远无法达到共识,而在TCP三路握手中可以? 今天抽出了一些时间进行研究发现,实际上TCP三路握手也不是完全可靠的,只是一个近似 ...
- .NET大批量插入数据到Oracle
跟一个第三方系统做接口,需要插入几百万条数据到Oracle数据库. 下载Oracle的Managed版本的ODP.NET组件,只需要一个Oracle.ManagedDataAccess.dll这个DL ...
- MySQL实现批量检查表并进行repair与optimize的方法
这篇文章主要介绍了MySQL实现批量检查表并进行repair与optimize的方法,结合实例形式分析了MySQL批量修复与优化表的相关技巧,需要的朋友可以参考下 本文实例讲述了MySQL实现批量检查 ...
- dubbo 面试
1.使用dubbo+zookeeper ,如果注册中心挂掉,是否可以继续通信?(zk集群可以达到高可用,但是如果全部挂掉呢?) 我答了不可以吧(项目没用过,自学没又这深度) 正确答案: dubbo使用 ...
- CSRF 和 XSS 的区别
XSS 利用的是用户对指定网站的信任,CSRF 利用的是网站对用户网页浏览器的信任 XSS: 跨站脚本攻击 原名为Cross Site Scriptin,为避免和网页层级样式表概念混淆, 另名为XSS ...
- Ambari2.6.2 HDP2.6.5 大数据集群搭建
Ambari 2.6.2 中 HDFS-2.7.3 YARN-2.7.3 HIVE-1.2.1 HBASE-1.1.2 ZOOKEEPER-3.4.6 SPARK-2.3.0 注:本文基于root用户 ...
- 牛客小白月赛13 小A的回文串(Manacher)
链接:https://ac.nowcoder.com/acm/contest/549/B来源:牛客网 题目描述 小A非常喜欢回文串,当然我们都知道回文串这种情况是非常特殊的.所以小A只想知道给定的一个 ...
- sql的日期和时间函数–date_format
Mysql的日期和时间函数–date_format DATE_FORMAT(date,format)依照 format 字符串格式化 date 值.下面的修饰符可被用于 format 字符串中:修 ...
- WebForm应用log4net记录错误日志——使用线程列队写入
我的项目结构如下图: 日志帮助类库需要log4net包:工具—NuGet包管理器—管理解决方案NuGet程序包 线程日志帮助类 FlashLogger.cs 代码 using System; usin ...
- linux回顾
linux内容回顾: centos6.9 ubuntu12 麒麟linux suse(德国linux) depin xshell(连接工具) vmware workstation(个人学习) ...