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;
    }
  • 相关阅读:
    centos7安装Python3.7,执行./configure时报错,configure: error: no acceptable C compiler found in $PATH
    Hadoop集群搭建
    jdk安装
    ssh免密登陆
    centos安装python3.7
    centos7更改yum源
    32.Java基础_异常
    31.Java基础_日期/日期格式/日历类
    1.华为路由交换技术_网络基础知识
    396. 旋转函数(数学)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/6188712.html
Copyright © 2011-2022 走看看