链接:

https://codeforces.com/contest/1271/problem/E

题意:

At first, let's define function f(x) as follows:

f(x)={x2x−1if x is evenotherwise

We can see that if we choose some value v and will apply function f to it, then apply f to f(v), and so on, we'll eventually get 1. Let's write down all values we get in this process in a list and denote this list as path(v). For example, path(1)=[1], path(15)=[15,14,7,6,3,2,1], path(32)=[32,16,8,4,2,1].

Let's write all lists path(x) for every x from 1 to n. The question is next: what is the maximum value y such that y is contained in at least k different lists path(x)?

Formally speaking, you need to find maximum y such that |{x | 1≤x≤n,y∈path(x)}|≥k.

思路:

假设当前值为x,是奇数,则可以从x2, x2+1,推出,接着是x4,x4+1,x4+2,x4+3...

如果是偶数,要多计算x+1。

然后可以二分枚举,但是没搞懂为什么要分奇偶数。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL; LL n, k; LL Check(LL x)
{
LL cnt = 1LL, tmp = 1LL;
while(x*2+tmp*2-1<= n)
{
x *= 2;
tmp *= 2;
cnt += tmp;
}
cnt += max(0LL, n-x*2+1);
return cnt;
} int main()
{
while(cin >> n >> k)
{
LL l = 0, r = (n-1)/2+1;
while(r-l>1)
{
LL mid = (l+r)/2;
if (Check(2*mid+1) >= k)
l = mid;
else
r = mid;
}
LL ans = 2*l+1;
l = 0, r = n/2+1;
while(r-l>1)
{
LL mid = (l+r)/2;
if (Check(2*mid)+Check(mid*2+1) >= k)
l = mid;
else
r = mid;
}
cout << max(ans, 2*l) << endl;
} return 0;
}

Codeforces Round #608 (Div. 2) E. Common Number的更多相关文章

  1. Codeforces Round #608 (Div. 2) E - Common Number (二分 思维 树结构)

  2. Codeforces Round #608 (Div. 2) E. Common Number (二分,构造)

    题意:对于一个数\(x\),有函数\(f(x)\),如果它是偶数,则\(x/=2\),否则\(x-=1\),不断重复这个过程,直到\(x-1\),我们记\(x\)到\(1\)的这个过程为\(path( ...

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #608 (Div. 2)

    传送门 A. Suits 签到. Code /* * Author: heyuhhh * Created Time: 2019/12/15 17:16:33 */ #include <iostr ...

  5. Codeforces Round #427 (Div. 2) B. The number on the board

    引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...

  6. Codeforces Round #585 (Div. 2) B. The Number of Products(DP)

    链接: https://codeforces.com/contest/1215/problem/B 题意: You are given a sequence a1,a2,-,an consisting ...

  7. Codeforces Round #608 (Div. 2) D. Portals

    链接: https://codeforces.com/contest/1271/problem/D 题意: You play a strategic video game (yeah, we ran ...

  8. Codeforces Round #411 div 2 D. Minimum number of steps

    D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...

  9. Codeforces Round #117 (Div. 2) D.Common Divisors(KMP最小循环节)

    http://codeforces.com/problemset/problem/182/D 题意:如果把字符串a重复m次可以得到字符串b,那么我们称字符串a为字符串b的一个因子,现在给定两个字符串S ...

随机推荐

  1. java.sql.SQLException: Access denied for user 'root'@'10.10.7.180' (using password: YES)

    1.刚开始连接数据库提示是: java.sql.SQLException: Access denied for user 'root'@'10.10.7.180' (using password: N ...

  2. Replace Words

    In English, we have a concept called root, which can be followed by some other words to form another ...

  3. [转帖]FreeBSD、OpenBSD、NetBSD的区别

    FreeBSD.OpenBSD.NetBSD的区别 Linux 的历史 http://www.361way.com/unix-bsd/1513.html   一直unix在我心目中的地位都很高,uni ...

  4. [转帖]开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别

    开源许可证GPL.BSD.MIT.Mozilla.Apache和LGPL的区别 https://www.geek-workshop.com/thread-1860-1-1.html     liamj ...

  5. python基础之初始函数

    首先,为什么要使用函数? 函数的本质来说,就是写一串代码具有某些功能,然后封装起来,接下来可以很方便的调用 例如...然后... # s = '金老板小护士'# len(s) #在这里需求是求字符串s ...

  6. Android开发build出现java.lang.NumberFormatException: For input string: "tle 0x7f0800aa"错误的解决方案

    查看异常栈没有发现项目代码的问题,因为问题是出现在layout文件中. 全局查找tle这个,发现在某个layout文件中title一词被变成ti tle了,结果Android就xjb报错了. 参考

  7. Thinkphp5.0快速入门笔记(3)

    学习来源与说明 https://www.kancloud.cn/thinkphp/thinkphp5_quickstart 测试与部署均在windows10下进行学习. 快速入门第三节 获取当前的请求 ...

  8. maven项目转换为gradle项目

    进入到项目更目录,运行 gradle init --type pom 上面的命令会根据pom文件自动生成gradle项目所需的文件和配置,然后以gradle项目重新导入即可.

  9. ajax实现异步操作实例1

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. Yii2 增删查改

    查: User::find()->all();    //返回所有用户数据:User::findOne($id);   //返回 主键 id=1  的一条数据: User::find()-> ...