Codeforces Round #384 (Div. 2)B. Chloe and the sequence 数学
B. Chloe and the sequence
题目链接
http://codeforces.com/contest/743/problem/B
题面
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element equal to 1. Then we perform (n - 1) steps. On each step we take the sequence we've got on the previous step, append it to the end of itself and insert in the middle the minimum positive integer we haven't used before. For example, we get the sequence [1, 2, 1] after the first step, the sequence [1, 2, 1, 3, 1, 2, 1] after the second step.
The task is to find the value of the element with index k (the elements are numbered from 1) in the obtained sequence, i. e. after (n - 1) steps.
Please help Chloe to solve the problem!
输入
The only line contains two integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2n - 1).
输出
Print single integer — the integer at the k-th position in the obtained sequence.
样例输入
3 2
样例输出
2
题意
假设现在的数列是a,那么在a的背后放一个最小的没出现过的整数,然后再把a重复的放在后面。
然后现在问你p位置是什么
题解
直接按照题意模拟迭代下去也可以……
但实际上就是这个p数字的二进制最小的1的位数的位置。
代码
#include<bits/stdc++.h>
using namespace std;
long long n,p;
int main()
{
scanf("%lld%lld",&n,&p);
cout<<log2(p&(-p))+1<<endl;
}
Codeforces Round #384 (Div. 2)B. Chloe and the sequence 数学的更多相关文章
- Codeforces Round #384 (Div. 2) B. Chloe and the sequence(规律题)
传送门 Description Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems ...
- Codeforces Round #384 (Div. 2)D - Chloe and pleasant prizes 树形dp
D - Chloe and pleasant prizes 链接 http://codeforces.com/contest/743/problem/D 题面 Generous sponsors of ...
- Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (思维)
Codeforces Round #529 (Div. 3) 题目传送门 题意: 给你由左右括号组成的字符串,问你有多少处括号翻转过来是合法的序列 思路: 这么考虑: 如果是左括号 1)整个序列左括号 ...
- Codeforces Round #384 (Div. 2) //复习状压... 罚时爆炸 BOOM _DONE
不想欠题了..... 多打打CF才知道自己智商不足啊... A. Vladik and flights 给你一个01串 相同之间随便飞 没有费用 不同的飞需要费用为 abs i-j 真是题意杀啊, ...
- Codeforces Round #384 (Div. 2)A,B,C,D
A. Vladik and flights time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #384 (Div. 2) A B C D dfs序+求两个不相交区间 最大权值和
A. Vladik and flights time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题
C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...
- Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)
传送门 Description Vladik and Chloe decided to determine who of them is better at math. Vladik claimed ...
- Codeforces Round #384 (Div. 2)D-Chloe and pleasant prizes
D. Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input ...
随机推荐
- js脚本放置位置
若是display:none:则元素height.width为0:但去了display:none后,恢复原来大小,所以操作元素应该在去除display:none后.
- cloudera manager安装步骤小结
1.准备三台虚拟机,系统是centos 7,IP分别是: 192.168.254.110 master 192.168.254.111 slave1 192.168.254.112 slave2 2. ...
- html写法对gzip压缩率的影响
前几天在群里看到小杜分享一篇文章,<html写法对gzip压缩率的影响>,为此我也对这点分析了一下.不知道大家有没有看过这文章,作者是来自微博懒懒交流会,其内容我这里先简述一下. Gzip ...
- C++ 无法将值写入注册表 HKEY_LOCAL_MACHINE\Sofeware\Microsoft\Windows\CurrentVersion\Run,以实现开机自启动应用程序。
C++ 无法将值写入注册表 HKEY_LOCAL_MACHINE\Sofeware\Microsoft\Windows\CurrentVersion\Run,以实现开机自启动应用程序.但可以写入到H ...
- 新公司入职第一天遇到的 关于 CSS 单行溢出文本显示省略号...的问题
上班第一天 前端岗位,因为公司这个项目是标准开发 所以没法用框架在打架页面,好吧 我手写 各种div 各种css样式 好不忧伤,好吧 不废话了 进入正题. 想在导航栏中的 客户信息 功能点 实现溢出用 ...
- jsonp与ajax
jsonp思维导图:1.定义2.为什么用3.json原理4.优缺点何为跨域?何为JSONP?JSONP技术能实现什么?是否有必要使用JSONP技术? JSON和JSONP??虽然只有一个字母的差别,但 ...
- SpringMVC文件上传实现
SpringMVC(注解)上传文件需要注意的几个地方:1.form的enctype="multipart/form-data",这个是上传文件必须的2.applicationCon ...
- error at ::0 can't find referenced pointcut解决办法(转载)
原文:http://blog.sina.com.cn/s/blog_9ecb0d9d0101fheg.html Spring中采用annotation的方式实现AOP代理,运行测试代码时抛出以下异常: ...
- PAIP.并发编程 多核编程 线程池 ExecutorService的判断线程结束
PAIP.并发编程 多核编程 线程池 ExecutorService的判断线程结束 ExecutorService并没有提供什么 isDone()或者isComplete()之类的方法. 作者Atti ...
- Atitit.guice3 ioc 最佳实践 o9o
Atitit.guice3 ioc 最佳实践 o9o 1. Guice的优点and跟个spring的比较 1 2. 两个部分:::绑定and注入@Inject 1 3. 绑定所有的方法总结 2 3. ...