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 ...
随机推荐
- Leetcode之动态规划(DP)专题-392. 判断子序列(Is Subsequence)
Leetcode之动态规划(DP)专题-392. 判断子序列(Is Subsequence) 给定字符串 s 和 t ,判断 s 是否为 t 的子序列. 你可以认为 s 和 t 中仅包含英文小写字母. ...
- 激活后出现grab>
最近由于经常整理自己电脑上的文件,难免都会遇到误删系统文件或者操作失误导致系统不能够正常进入的情况.这时就会出现grub错误的提示,只能输入命令才能进入系统.那么该输入什么命令呢?其实非常简单. gr ...
- 如何用快排思想在O(n)内查找第K大元素--极客时间王争《数据结构和算法之美》
前言 半年前在极客时间订阅了王争的<数据结构和算法之美>,现在决定认真去看看.看到如何用快排思想在O(n)内查找第K大元素这一章节时发现王争对归并和快排的理解非常透彻,讲得也非常好,所以想 ...
- [c++] 链表各类操作详解
链表概述 链表是一种常见的重要的数据结构.它是动态地进行存储分配的一种结构.它可以根据需要开辟内存单元.链表有一个“头指针”变量,以head表示,它存放一个地址.该地址指向一个元素.链表中每一个元素称 ...
- Elasticsearch Metric聚合
首先查看index文档信息 $ curl -XGET "http://172.16.101.55:9200/_cat/indices?v" 输出 health status ind ...
- mysql拆分逗号一列变多行
需求: SELECT ), ) FROM TABLE a INNER JOIN mysql.help_topic b )
- 【转】.NET Core + Ocelot + IdentityServer4 + Consul 基础架构实现
作者:Zhang_Xiang 原文地址:.NET Core + Ocelot + IdentityServer4 + Consul 基础架构实现 先决条件 关于 Ocelot 针对使用 .NET 开发 ...
- 房地产大佬潘石屹推荐学Python编程,这本从0到1就够了
潘石屹推荐学Python编程,很多人都不相信,他的微博真真切切. 连房地产都开始学Python了,因为要听懂机器,让机器为我所用. 再不学习Python真的晚了!!!! 如何学? 怎么学? 还是推荐高 ...
- Spring防止Xss配置
web.xml配置 <!-- xss过滤器 --> <filter> <filter-name>XssFilter</filter-name> < ...
- leecode刷题(31) -- 回文数
leecode刷题(31) -- 回文数 回文数 判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输 ...