二分答案。

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

  先倍增序列,通过 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. 【iOS】edgesForExtendedLayout

    在 iOS 7.0 中,苹果引入了一个新的属性,叫做 edgesForExtendedLayou,它的默认值为 UIRectEdgeAll. 当你的容器是 navigationController 时 ...

  2. 【经验分享】ASP.NET 的 Page_Load 执行了2次,真的!

    发现问题 这是来自一位网友的提问: 本着求真务实的态度,我打开了 AppBoxPro 项目,本地调试果然发现 Page_Load 进入了两次! 其实在没测试之前,我就有了大概的方向,因为AppBoxP ...

  3. 使用阿里云对docker拉取镜像加速

    使用docker的时候,总是需要去search镜像,使用国外的源下载太慢,还有诸多的限制,无意中发现可以使用阿里云进行加速,实测有用,废话少说,操作如下: 1.打开阿里云控制台,没有的可以用淘宝账号或 ...

  4. Linux常用的命令及使用方法

    1.请用命令查出ifconfig命令程序的绝对路径 [root@localhost ~]# which ifconfig(ifconfig是linux中用于显示或配置网络设备(网络接口卡)的命令) / ...

  5. Zabbix利用Windows性能监视器监控各项资源指标

    zabbix自带的windows监控模板并没有监控windows cpu使用率的监控 在cmd命令输入perfmon 打开后默认就一项CPU占用的监控,下面以添加硬盘空闲时间做示例 1:监控图形上面右 ...

  6. JDK容器类List,Set,Queue源码解读

    List,Set,Queue都是继承Collection接口的单列集合接口.List常用的实现主要有ArrayList,LinkedList,List中的数据是有序可重复的.Set常用的实现主要是Ha ...

  7. vagrant 创建虚拟机时遇到问题

    问题1 :  ceph-node3: Warning: Authentication failure. Retrying.. 问题分析: ssh 认证失败,在向虚拟机拷贝内容时权限不足. 解决办法: ...

  8. java课堂 动手动脑2

    1.编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数 Modulus=231-1=int.MaxValue, Multiplier=75=16807. C=0 当显示过231-2个数 ...

  9. 洛谷P2125 题解

    吐槽: 只能说这道题很数学,本数学蒟蒻推了半天没推出来,只知道要用绝对值,幸亏教练提醒,才勉强想出正解(似乎不是这样的),真的是很无语. 以上皆为吐槽本题,可直接 跳过 分析: 既然题目是要使书架上的 ...

  10. React 如何搭建脚手架

    React 如何搭建脚手架   npm install -g create-react-app    //安装 create-react-app react-demo    // react-demo ...