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 ...
随机推荐
- 多线程JAVA篇(一)
解析AsyncTask源码之前,首先讲述与之相关的Java线程知识: 知识点清单 1.Thread类 2.Runnable接口 3.Callable接口 4.synchronized关键字 5.vol ...
- 关于Repository模式
定义(来自Martin Fowler的<企业应用架构模式>): Mediates between the domain and data mapping layers using a co ...
- log4j.properties example
google search log4j.properties example Output to Console # Root logger option log4j.rootLogger=INFO, ...
- 一些CSS常见的小问题小笔记
父元素与子元素之间的margin-top问题: 给子元素盒子一个垂直外边距margin-top,父元素盒子也会往下走margin-top的值 解决方法: 1.修改父元素的高度,增加padding-to ...
- HibernateDaoSupport类的使用
HibernateDaoSupport类的使用 1. 继承了HibernateDaoSupport类的类获取session时,已不可用SessionFactory.OpenSessioo ...
- Virtualbox修改bios信息安装Windows XP OEM
转载 http://hi.baidu.com/guoyao11/item/631ad6eb4fb3d93887d9de11 具体方法有两个: 1.把下面的代码复制改后缀为BAT文件直接运行即可,以Le ...
- centos 安装PGSQL
centos 安装PGSQLCentOS下yum安装PostgreSQL目录 1 Configure YUM repository2 Install PGDG RPM file3 Install Po ...
- Centos6.5 下安装PostgreSQL9.4数据库
一.安装PostgreSQL源 CentOS 6.x 32bit rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-i386/pgdg-cent ...
- IP协议
因特网协议(Internet Protocol, IP)是Internet的核心协议之一, 工作在网络层.IP协议提供节点间的寻址,路由以及顺序控制, 流量控制等服务. IP协议分为IPv4和IPv6 ...
- BugTracker 功能说明(有图有真相)
一.简单介绍 BugTracker是基于Asp.Net,C#, SqlServer的一个web端Bug管理系统.发布在IIS上.能够对不同项目,不同组织,不同人员的bug进行管理和更新设计优先级和用户 ...