Christmas 蔚落 2023-07-13 03:20 22阅读 0赞 > 题目描述 > 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 is given from Standard Input > in the following format: > > N X > > 输出 Print the number of patties in the bottom-most X layers from the > bottom of a level-N burger. > > 样例输入 Copy 2 7 样例输出 Copy 4 很明显是一道典型的递归题: 可以发现burger是对称的。那么就可以分段递归。 len是每个burger的长度(高度),p记录的是每个burger含有的p的个数。 两个公式稍微推一下就可以得到,是一个等比数列的问题。(事实上直接迭代也可以得到) 上代码: #include <cstdio> #include <cmath> #include <iostream> using namespace std; typedef unsigned long long ll; ll p[55], len[55]; ll solve(ll n, ll x) { if(x <= n) return 0; if(x >= len[n]-1) return p[n]; if(x == len[n]/2+1) return (p[n]/2+1); else if(x < len[n]/2+1) return solve(n-1,x-1); else return p[n]/2+1 + solve(n-1, x-len[n]/2-1); } int main() { for(int i = 0; i <= 50; ++i) { p[i] = pow(2, i+1)-1; len[i] = pow(2, i-1)*8-3; } ll n,x; cin>>n>>x; cout<<solve(n,x)<<endl; return 0; } ![这里参考大佬写的递归][watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2NDk3NDIz_size_16_color_FFFFFF_t_70] 谢谢! [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2NDk3NDIz_size_16_color_FFFFFF_t_70]: https://img-blog.csdnimg.cn/20200309211441688.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzE2NDk3NDIz,size_16,color_FFFFFF,t_70
相关 Christmas > 题目描述 > In some other world, today is Christmas. > Mr. Takaha decides to make a mul 蔚落/ 2023年07月13日 03:20/ 0 赞/ 23 阅读
相关 poj 3710——Christmas Game 题意: 给定多个无向有环图,两个人在树上博弈,问博弈结果。 思路: 如果没有环,则是一个标准的树上博弈,那么满足 1. 叶子节点的sg为0 2. 中间节点的sg为 喜欢ヅ旅行/ 2022年07月15日 08:56/ 0 赞/ 161 阅读
相关 poj-3013-Big Christmas Tree Big Christmas Tree <table> <tbody> <tr> <td><strong>Time Limit:</strong> 妖狐艹你老母/ 2022年05月19日 00:37/ 0 赞/ 142 阅读
相关 F - Christmas Spruce 题目描叙: Consider a rooted tree. A rooted tree has one special vertex called the root. A 谁践踏了优雅/ 2022年04月01日 12:12/ 0 赞/ 153 阅读
相关 圣诞快乐,Merry Christmas 易网库全体员工祝大家圣诞快乐~~ Merry Christmas 同时提醒一下大家,我们的圣诞75折优惠活动12月25日截止哦,所以大家要抓紧时间购买空间啦~~~ 转载于 ╰+攻爆jí腚メ/ 2021年12月11日 01:37/ 0 赞/ 256 阅读
还没有评论,来说两句吧...