链接:

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. 关于Pytorch中accuracy和loss的计算

    这几天关于accuracy和loss的计算有一些疑惑,原来是自己还没有弄清楚. 给出实例 def train(train_loader, model, criteon, optimizer, epoc ...

  2. NoSQL--leveldb

    什么是leveldb: leveldb它是一个 NOSQL 存储引擎,它和 Redis 不是一个概念.Redis 是一个完备的数据库,而 LevelDB 它只是一个引擎. LevelDB 还可以将它看 ...

  3. 微服务之服务注册与发现--Eureka(附代码)

    该贴为入门贴,看完可快速知道服务注册与发现是什么?怎么用?至于深入的内容不在此篇文章所述之内,请自行百度. 内容来自:https://blog.csdn.net/nanbiebao6522/artic ...

  4. git与码云关联教程

    注:我用的这种方法是利用“公钥”使本地仓库与码云建立起联系,从而不需要用户名与密码的方法. 1.首先,创建好码云,再在码云上创建好个人仓库,然后复制好仓库地址,这里的地址是指“SSH”类型的. 2.下 ...

  5. centos7基础安装

    基础: hostname xxvim /etc/hostname systemctl stop firewalld systemctl disable firewalldsetenforce 0gre ...

  6. mysql连接数据库时报2003错误怎么解决

    mysql 2003是连接错误,连不上服务器. 你目前可以如下方法:进入控制面板->服务管理(我的是管理工具),->服务,然后找到Mysql服务,右键修改属性,改为自启动,以后再重启就没有 ...

  7. sql server truncate语句

    truncate语句 --truncate table '表名' --这样就利用SQL语句清空了该数据表,而不保留日志

  8. 第二篇 jQuery 选择器

    2-1,2  table隔行变色 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...

  9. O006、CPU和内存虚拟化原理

    参考https://www.cnblogs.com/CloudMan6/p/5263981.html   前面我们成功的把KVM跑起来了,有了些感性认识,这个对于初学者非常重要.不过还不够,我们多少要 ...

  10. 12 Python之函数进阶

    1. 动态传参 *, ** : 形参: 聚合 位置参数* -> 元组 def func(*args, a, b, c): print(a, b , c, args) func(1,2,3,4,5 ...