zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    基于python检测端口是否在使用
    一行CMD命令kill(杀)掉你的进程
    Python 线程与进程
    Linux07 文件查找(locate、find )及特殊权限(SUID、SGID、Sticky)
    Linux06 vim文本编辑器的使用
    Linux04 shell编程1
    Linux03 重定向,管道,文件查找(grep)
    Linux02(目录、文件、用户、用户组管理)
    Linux01
    pytest装饰器
  • 原文地址:https://www.cnblogs.com/qscqesze/p/6188712.html
Copyright © 2011-2022 走看看