Codeforces Round #608 (Div. 2) E. Common Number
链接:
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的更多相关文章
- Codeforces Round #608 (Div. 2) E - Common Number (二分 思维 树结构)
- Codeforces Round #608 (Div. 2) E. Common Number (二分,构造)
题意:对于一个数\(x\),有函数\(f(x)\),如果它是偶数,则\(x/=2\),否则\(x-=1\),不断重复这个过程,直到\(x-1\),我们记\(x\)到\(1\)的这个过程为\(path( ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #608 (Div. 2)
传送门 A. Suits 签到. Code /* * Author: heyuhhh * Created Time: 2019/12/15 17:16:33 */ #include <iostr ...
- Codeforces Round #427 (Div. 2) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
- 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 ...
- Codeforces Round #608 (Div. 2) D. Portals
链接: https://codeforces.com/contest/1271/problem/D 题意: You play a strategic video game (yeah, we ran ...
- 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 ...
- Codeforces Round #117 (Div. 2) D.Common Divisors(KMP最小循环节)
http://codeforces.com/problemset/problem/182/D 题意:如果把字符串a重复m次可以得到字符串b,那么我们称字符串a为字符串b的一个因子,现在给定两个字符串S ...
随机推荐
- SQL Injection(Blind)
SQL Injection(Blind),即SQL盲注,与一般注入的区别在于,一般的注入攻击者可以直接从页面上看到注入语句的执行结果,而盲注时攻击者通常是无法从显示页面上获取执行结果,甚至连注入语句是 ...
- C#实现多线程的方式:使用Parallel类
简介 在C#中实现多线程的另一个方式是使用Parallel类. 在.NET4中 ,另一个新增的抽象线程是Parallel类 .这个类定义了并行的for和foreach的 静态方法.在为 for和 f ...
- Flume 概念、模型和特点
Flume Event - Flume 事件 - 被定义为一个具有有效荷载的字节数据流和可选的字符串属性集. Flume Agent- Flume - 代理 - 是一个进程承载从外部源事件流到下一个目 ...
- superset连接sqlite频繁断开
出现上述现象的原因是SQLite只支持库级锁,不支持并发执行写操作,即使是不同的表,同一时刻也只能进行一个写操作.例如,事务T1在表A新插入一条数据,事务T2在表B中更新一条已存在的数据,这两个操作是 ...
- hashMap怎样解决hash冲突
通过链表的方式处理: java1.7是单向链表 jvav1.8在数量小于8时是单向链表,大于8就是红黑树,查找方式遍历判断 解决冲突的方式很多,例如再hash,再散列(开放地址法,探测再散列)
- js实现复制内容到剪贴板
一. 原生js实现,电脑可以用,手机不可以用 1. 必须是 input元素 才可以使用 <input id="code" type="text" valu ...
- Maven将java打包成jar并且运行笔记
Maven项目打包成jar并且运行笔记 首先创建一个maven项目 运行成功后,有两种方式将项目进行打包. 第一种方式: 在IDEA编辑器中maven项目进行打包: 这里显示jar包中没有主清单属性, ...
- typeof,instanceof的区别,扩展知识:显示原型(prototype)与隐式类型(__protot__)
3.typeof 和instanceof区别 1.typeof 主要用于判断对象类型 console.log(typeof null) //object console.log(typeof unde ...
- win7(64位旗舰版)visual studio 2017无法安装及vs2015闪退问题解决方式
折腾了两天,几乎试了网上说的所有方法(就差重装系统了,看到有人说重装系统之后还是同样的问题,果断放弃重装),visual studio 2017的安装问题终于解决了,为了帮助同样还在折腾的初级开发者们 ...
- 安装Maatwebsite \ EXCEL \ ExcelServiceProvider
安装时报错 composer You can also run `php --ini` inside terminal to see which files are used by PHP in CL ...