【47.40%】【codeforces 743B】Chloe and the sequence
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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!
Input
The only line contains two integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 2n - 1).
Output
Print single integer — the integer at the k-th position in the obtained sequence.
Examples
input
3 2
output
2
input
4 8
output
4
Note
In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4.
【题目链接】:http://codeforces.com/contest/743/problem/B
【题解】
如果k==2^(n-1)则直接输出.
否则递归搞一下就可以了。(因为处理的都是相同的问题);
如果在左边k就变成k-2^(n-1);否则还是k.
n的话固定-1;
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
//const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
int n;
LL k;
LL pre[51];
void solve(int n,LL k)
{
if (k==pre[n-1])
cout << n << endl;
else
if (k < pre[n-1])
solve(n-1,k);
else
solve(n-1,k-pre[n-1]);
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
pre[0] = 1;
rep1(i,1,50)
pre[i] = pre[i-1]*2;
rei(n);rel(k);
solve(n,k);
return 0;
}
【47.40%】【codeforces 743B】Chloe and the sequence的更多相关文章
- 【47.40%】【BZOJ 1875】[SDOI2009]HH去散步
Time Limit: 20 Sec Memory Limit: 64 MB Submit: 1363 Solved: 646 [Submit][Status][Discuss] Descript ...
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【66.47%】【codeforces 556B】Case of Fake Numbers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【40.17%】【codeforces 569B】Inventory
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【47.95%】【codeforces 554C】Kyoya and Colored Balls
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【27.40%】【codeforces 599D】Spongebob and Squares
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【42.59%】【codeforces 602A】Two Bases
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【51.27%】【codeforces 604A】Uncowed Forces
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【34.88%】【codeforces 569C】Primes or Palindromes?
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- RK3066 实现LED闪烁的代码分析
实现LED灯的闪烁,须要在驱动里加入一个定时器函数,详细实现涉及到了LED GPIO驱动.用户空间程序调用驱动程序. 1.首先来看LED设备驱动注冊过程,代码位于../kernel/drivers/l ...
- CCNP路由实验之十五 NAT(网络地址转换)
CCNP路由实验之十五 NAT(网络地址转换) 众所周知,要让自己的电脑连上Internet,必须要到运营商(ISP)申请一个上网账号,依据此账号申请自己的宽频业务(拨号上网.商业固定IP等等) ...
- 通过wireshark,以及python代码收发邮件,了解smtp协议,pop协议工作过程
40返回连接server成功 41.43发送ehlo命令查询server支持命令 返回250 44.46请求认证 server响应235认证成功 47.49发送mail命令发送者邮箱 返回250 ...
- 分析深圳电信的新型HTTP劫持方式
昨天深圳下了一天的暴雨,2014年的雨水真是够多的. 用户的资源就是金钱,怎的也要好好利用嘛不是? ISP的劫持手段真是花样百出.从曾经的DNS(污染)劫持到后来的共享检測.无不通过劫持正常的请求来达 ...
- GridView-属性大全
这是个网格控件 他的实现也是通过adapter来实现的,感觉跟listview在使用上并没有多大的区别 常见属性如下 1.android:numColumns=”auto_fit” //GridVie ...
- Manning.EJB.3.in.Action.2nd.Edition
Manning.EJB.3.in.Action.2nd.Edition http://files.cnblogs.com/files/rojas/EJB_3_in_Action_2nd_Edition ...
- Linux启动(续)
runlevel (启动级别): 查看命令 :who -r 或 runlevel 0:halt 关机 1:单用户模式,直接以管理员身份登录,不需要密码 ...
- 让人难过的 openssl_pkcs7_encrypt
让人难过的 openssl_pkcs7_encrypt 用PHP.NET的范例,没有加密结果,也没有报错信息,而openssl_pkcs7_sign()函数则返回 error opening inpu ...
- Android Unable to execute dex: method ID not in [0, 0xffff]: 65536 问题解决方法
开始一个新项目的时候,Build工程的时候一直报这个错误: 控制台报错误:Conversion to Dalvik format failed: Unable to execute dex: meth ...
- golang encoding/json
package main import ( "bytes" "encoding/json" "fmt" ) type ColorGroup ...