链接:

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. Ubuntu强制修改root密码

    Ubuntu忘记超级用户root密码并重新设置密码 解决方法如下: 第一种方法——不进入recovery mode设置(推荐) 说明案例:Ubuntu版本:Ubuntu 16.04.3 LTS Ste ...

  2. web端 微软 RDLC 报表插件 宽大于高 横向打印失效 解决方案

    起因于系统报表工具使用的RDLC,本地测试一直使用的纵向打印,未测试过横向打印

  3. mac sudo异常

    dsenableroot -d -u <your_admin_username> -p <your_password>  

  4. 关于moment().format()

    链接在这儿http://momentjs.cn/ 想要获取单独的年份或者月份可以使用:   moment().format('YYYY')和moment().format('MM') 随手记一下...

  5. 第四周课程总结&试验报告2

    试验报告2 写一个名为Rectangle的类表示矩形.其属性包括宽width.高height和颜色color,width和height都是double型的,而color则是String类型的.要求该类 ...

  6. Java小程序—录屏小程序(下半场)

    下半场. 上半场,我们我们写了录屏的程序,那么下半场我们的任务是写一个播放器. 设计思路:播放器的思路就是将图片放在一个JScrollPane中顺序播放,所以还是得使用swing组件,并且仍然要使用线 ...

  7. Linux-1.3目录结构,基础命令

    1.Linux目录结构 2.Linux基础命令(常用) ctrl+alt+T(打开终端) cd 切换文件夹(pwd查看当前目录) cd /home 绝对路径 以根目录开头 cd admin 相对路径 ...

  8. Python 东方财富网-股市行情数据抓取

    东方财富网 股市行情数据抓取: http://quote.eastmoney.com/center/gridlist.html#hs_a_board 请求数据未入库处理,其中数据只存入数据文本,未做存 ...

  9. jQuery选择器引入

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  10. 帝国cms 重置用户名和密码

    5.1至7.0版本:用phpmyadmin修改phome_enewsuser表里的记录:把password字段的值设为:“322d3fef02fc39251436cb4522d29a71”:把salt ...