二分答案。

对于每次二分后的答案来说,

  先倍增序列,通过 two point 来找到 以每个点为起点的最优的符合答案的在哪里。

  然后可以DFS树去判断他的前k祖先之间的距离是不是大于k。 常数有点大。

  在 ID为 WuHongxun 的代码下学会了, 先判断一下最小一段的跨度, 如果跨度 >= n / k + 1 那么直接就是合法的了。

  否则枚举最小跨度内的点作为起点, 直接走k步, 判断一下是否合法。

  因为假定最小跨度的区间为 [l, r]。

  必定不存在一个合法区间[a, b] 使得 a < l && b > r。 所以因为没有一种区间方式覆盖这个区间, 故在这个区间内一定会有一个点被作为起点。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 2e6 + ;
LL L = << ;
int n, k, seed, add;
LL d[N], s[N];
int nt[N];
inline LL cal(int l, int r){
return (s[r] - s[l+r>>]) - (s[(l+r-)>>] - s[l-]);
}
bool check(LL x){
int mn = * n + , id;
for(int i = , j = ; i <= n * ; ++i){
while(j <= * n && cal(i,j) <= x) ++j;
nt[i] = j;
if(i <= n && j-i < mn){
mn = j - i;
id = i;
}
}
if(mn >= n/k + ) return true;
for(int i = id, ed = nt[i]%n+; i != ed; i = i%n +){
int z = i;
for(int j = ; j <= k; ++j){
z = nt[z];
if(i + n <= z) return true;
}
}
return false; }
void Ac(){
scanf("%d%d", &n, &k);
scanf("%d%d", &seed, &add);
for(int i = ; i <= n; ++i){
seed = (seed * + add) & (L-);
d[i] = seed;
}
sort(d+, d++n);
for(int i = ; i <= n; ++i)
d[i+n] = d[i] + L;
for(int i = ; i <= *n; ++i)
s[i] = s[i-] + d[i];
LL l = , r = L * n / k;
while(l <= r){
LL mid = l+r >> ;
if(!check(mid)) l = mid + ;
else r = mid - ;
}
cout << l << endl;
return ;
}
int main(){
Ac();
return ;
}

Gym 100956 A Random Points on the Circle的更多相关文章

  1. [Swift]LeetCode478. 在圆内随机生成点 | Generate Random Point in a Circle

    Given the radius and x-y positions of the center of a circle, write a function randPoint which gener ...

  2. [LeetCode] Generate Random Point in a Circle 生成圆中的随机点

    Given the radius and x-y positions of the center of a circle, write a function randPoint which gener ...

  3. 【LeetCode】478. Generate Random Point in a Circle 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/generate ...

  4. 478. Generate Random Point in a Circle

    1. 问题 给定一个圆的半径和圆心坐标,生成圆内点的坐标. 2. 思路 简单说 (1)在圆内随机取点不好做,但是如果画出这个圆的外接正方形,在正方形里面采样就好做了. (2)取两个random确定正方 ...

  5. [LeetCode] Random Pick with Blacklist 带黑名单的随机选取

    Given a blacklist B containing unique integers from [0, N), write a function to return a uniform ran ...

  6. [LeetCode] Random Flip Matrix 随机翻转矩阵

    You are given the number of rows n_rows and number of columns n_cols of a 2D binary matrix where all ...

  7. [LeetCode] Random Point in Non-overlapping Rectangles 非重叠矩形中的随机点

    Given a list of non-overlapping axis-aligned rectangles rects, write a function pick which randomly ...

  8. 【Checkio Exercise】Three Point Circle

    计算三角形外接圆的函数: Three Point Circle If we want to build new silos, then we need to make more formal and ...

  9. 519. Random Flip Matrix(Fisher-Yates洗牌算法)

    1. 问题 给定一个全零矩阵的行和列,实现flip函数随机把一个0变成1并返回索引,实现rest函数将所有数归零. 2. 思路 拒绝采样 (1)先计算矩阵的元素个数(行乘以列),记作n,那么[0, n ...

随机推荐

  1. python交互界面无法使用方向键

    问题 python交互界面无法使用方向键,按方向键全变成^[[^C这类型的字符 解决办法 办法1: 使用yum安装readline.readline-devel,然后重装python 这种方法太麻烦了 ...

  2. Mac Android 配置环境变量

    进入终端,输入以下命令: cd ~ touch .bash_profile //没有该文件的话新建一个 vi .bash_profile //vim 形式打开 输入内容jdk变量配置内容: expor ...

  3. Jenkins Java 反序列化远程执行代码漏洞(CVE-2017-1000353)

    Jenkins Java 反序列化远程执行代码漏洞(CVE-2017-1000353) 一.漏洞描述 该漏洞存在于使用HTTP协议的双向通信通道的具体实现代码中,jenkins利用此通道来接收命令,恶 ...

  4. java之Arrays.asList

    使用Arrays.asList()的原因无非是想将数组或一些元素转为集合,而你得到的集合并不一定是你想要的那个集合. 而一开始asList的设计时用于打印数组而设计的,但jdk1.5开始,有了另一个比 ...

  5. 使用 Netty 实现一个 MVC 框架

    NettyMVC 上面介绍 Netty 能做是什么时我们说过,相比于 SpringMVC 等框架,Netty 没提供路由等功能,这也契合和 Netty 的设计思路,它更贴近底层.下面我们在 Netty ...

  6. STL set 详细用法

    一个集合(set)是一个容器,它其中所包含的元素的值是唯一的. 用到的库 #include <set> 定义 最简单: set<int> a; set和其他的stl一样,都支持 ...

  7. Unbutu在VMWare中挂载共享文件夹

    第一,安装VMTools,步骤自行搜索,安装成功后重启虚拟机. 第二,重启后,在虚拟机管理页面设置共享目录,选择总是启用,开启虚拟机. 第三,在终端进入挂载目录cd /mnt/hgfs/,通过命令su ...

  8. 解决socket粘包的两种low版模式 os.popen()和struct模块

    os.popen()模式 server端 import socket import os phone = socket.socket() # 实例化一个socket对象 phone.bind((&qu ...

  9. Mac 安装 homebrew 流程 以及 停在 Updating Homebrew等 常见错误解决方法

    懒人操作顺序:S_01>>>S_02>>>S_03 首先这是homebrew的官网 https://brew.sh/index_zh-cn 安装方法是在终端中输入 ...

  10. go 学习笔记之值得特别关注的基础语法有哪些

    在上篇文章中,我们动手亲自编写了第一个 Go 语言版本的 Hello World,并且认识了 Go 语言中有意思的变量和不安分的常量. 相信通过上篇文章的斐波那契数列,你已经初步掌握了 Go 语言的变 ...