Gym 100956 A Random Points on the Circle
二分答案。
对于每次二分后的答案来说,
先倍增序列,通过 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的更多相关文章
- [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 ...
- [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 ...
- 【LeetCode】478. Generate Random Point in a Circle 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/generate ...
- 478. Generate Random Point in a Circle
1. 问题 给定一个圆的半径和圆心坐标,生成圆内点的坐标. 2. 思路 简单说 (1)在圆内随机取点不好做,但是如果画出这个圆的外接正方形,在正方形里面采样就好做了. (2)取两个random确定正方 ...
- [LeetCode] Random Pick with Blacklist 带黑名单的随机选取
Given a blacklist B containing unique integers from [0, N), write a function to return a uniform ran ...
- [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 ...
- [LeetCode] Random Point in Non-overlapping Rectangles 非重叠矩形中的随机点
Given a list of non-overlapping axis-aligned rectangles rects, write a function pick which randomly ...
- 【Checkio Exercise】Three Point Circle
计算三角形外接圆的函数: Three Point Circle If we want to build new silos, then we need to make more formal and ...
- 519. Random Flip Matrix(Fisher-Yates洗牌算法)
1. 问题 给定一个全零矩阵的行和列,实现flip函数随机把一个0变成1并返回索引,实现rest函数将所有数归零. 2. 思路 拒绝采样 (1)先计算矩阵的元素个数(行乘以列),记作n,那么[0, n ...
随机推荐
- 洛谷 P5150 题解
题面 因为 n=lcm(a,b)n = lcm(a, b)n=lcm(a,b) ,可以得出: a 和 b 的质因数都是 n 的质因数 对于 n 的每个质因数 x ,在 n 中的次数为 y ,那么 ...
- 干货来了!python学习之重难点整理合辑1
关于装饰器.lambda.鸭子类型.魔法函数的理解仍存有困惑之处,趁周末有时间温故,赶紧去自学了解下相关知识. 1.装饰器是什么: 很多初学者在接触装饰器的时候只做到了肤浅的了解它的概念.组成形态.实 ...
- go 学习之路(二)
一.文件名 关键字 标识符 所有go源码都以.go结尾 标识符以字母或下划线开头,大小写敏感 a.boy b.Boy c.a+b d.0boy e._boy f.=_boy g._ 以上变量c.d.f ...
- dubbo文档笔记
配置覆盖关系 以 timeout 为例,显示了配置的查找顺序,其它 retries, loadbalance, actives 等类似: 方法级优先,接口级次之,全局配置再次之. 如果级别一样,则消费 ...
- 一份新的lilypond谱子,能设置页边距和设置换页符了
给学生做的一份乐谱,这回能设置页边距了,以及设置换页符了. 顺带能设置一些代码片段(snippet),可以用热键代替使用 设置页边距的snippet: \paper { %双引号里面填页面大小 #(s ...
- Python基础编程 内置函数
内置函数 内置函数(一定记住并且精通) print()屏幕输出 int():pass str():pass bool():pass set(): pass list() 将一个可迭代对象转换成列表 t ...
- 1关于如何用Navicat连接到xampp安装的mysql
打开xampp,打开config打开my.ini. 检索bind-address,后面的数字是你的IP地址 检索 port,后面的数字是端口号 打开Navicat新建连接,选中mysql 连接名随便起 ...
- Linux curl 命令详解
命令概要 该命令设计用于在没有用户交互的情况下工作. curl 是一个工具,用于传输来自服务器或者到服务器的数据.「向服务器传输数据或者获取来自服务器的数据」 可支持的协议有(DICT.FILE.FT ...
- hadoop安装解决之道
# 壹.故障现象 ```xml Microsoft Windows [版本 10.0.18362.239] (c) 2019 Microsoft Corporation.保留所有权利. C:\User ...
- Oracle中查看最近被修改过的表的方法
1.select uat.table_name from user_all_tables uat 该SQL可以获得所有用户表的名称 2.select object_name, created,last ...