bzoj 5163: 第k大斜率
5163: 第k大斜率
Time Limit: 10 Sec Memory Limit: 512 MB
Submit: 15 Solved: 4
[Submit][Status][Discuss]
Description
Input
Output
输出一行,包含一个整数,表示第k小的斜率向下取整的结果。
Sample Input
-1 -1
2 1
3 3
1 4
Sample Output
#include<bits/stdc++.h>
#define ll long long
#define maxn 100005
using namespace std;
int l,r,mid,ans;
const int inf=1000000000;
int px[maxn],ky;
struct node{
int x,y;
ll tmp; bool operator <(const node& u)const{
return tmp==u.tmp?x<u.x:tmp<u.tmp;
}
}a[maxn];
int n,m,f[maxn];
ll k; inline int query(int x){
int an=0;
for(;x;x-=x&-x) an+=f[x];
return an;
} inline void update(int x,int y){
for(;x<=ky;x+=x&-x) f[x]+=y;
} inline ll calc(){
ll an=0;
memset(f,0,sizeof(f)); for(int i=1;i<=n;i++) a[i].tmp=(ll)a[i].y-mid*(ll)px[a[i].x]; sort(a+1,a+n+1); for(int i=1;i<=n;i++){
an+=(ll)query(a[i].x-1);
update(a[i].x,1);
} return an;
} int main(){
scanf("%d%lld",&n,&k);
for(int i=1;i<=n;i++){
scanf("%d%d",&a[i].x,&a[i].y);
px[i]=a[i].x;
}
sort(px+1,px+n+1);
ky=unique(px+1,px+n+1)-px-1;
for(int i=1;i<=n;i++) a[i].x=lower_bound(px+1,px+ky+1,a[i].x)-px; l=-inf,r=inf;
while(l<=r){
mid=l+r>>1;
if(calc()>=k) ans=mid,l=mid+1;
else r=mid-1;
} printf("%d\n",ans);
return 0;
}
bzoj 5163: 第k大斜率的更多相关文章
- Luogu P4479 [BJWC2018]第k大斜率
一道清真简单的好写的题 Luogu P4479 题意 求点集两两连出的直线中斜率第$ k$大的直线 $ Solution$ 二分答案,设$x_j \geq x_i$ 若点$ (x_i,y_i)$和点$ ...
- [luogu4479][BJWC2018]第k大斜率【二维偏序+二分+离散化+树状数组】
传送门 https://www.luogu.org/problemnew/show/P4479 题目描述 在平面直角坐标系上,有 n 个不同的点.任意两个不同的点确定了一条直线.请求出所有斜率存在的直 ...
- BZOJ 2738 子矩阵第k大 | 二维树状数组 整体二分 分治
BZOJ 2738 "矩阵乘法"(子矩阵第k大) 题意 给出一个矩阵,多次询问子矩阵中第k大的数是多少. 题解 我做这道题之前先照着这道题出了一道题,是这道题的一维版本,在这里:h ...
- bzoj 3784: 树上的路径 堆维护第k大
3784: 树上的路径 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 88 Solved: 27[Submit][Status][Discuss] ...
- [BZOJ 3110] [Zjoi2013] K大数查询 【树套树】
题目链接: BZOJ - 3110 题目分析 这道题是一道树套树的典型题目,我们使用线段树套线段树,一层是区间线段树,一层是权值线段树.一般的思路是外层用区间线段树,内层用权值线段树,但是这样貌似会很 ...
- BZOJ.3110.[ZJOI2013]K大数查询(整体二分 树状数组/线段树)
题目链接 BZOJ 洛谷 整体二分求的是第K小(利用树状数组).求第K大可以转为求第\(n-K+1\)小,但是这样好像得求一个\(n\). 注意到所有数的绝对值\(\leq N\),将所有数的大小关系 ...
- BZOJ 3110: [Zjoi2013]K大数查询 [树套树]
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6050 Solved: 2007[Submit][Sta ...
- [LeetCode] Kth Largest Element in an Array 数组中第k大的数字
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...
- POJ2985 The k-th Largest Group[树状数组求第k大值+并查集||treap+并查集]
The k-th Largest Group Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 8807 Accepted ...
随机推荐
- 使用pip命令报You are using pip version 9.0.3, however version 18.0 is available pip版本过期.解决方案
使用pip命令安装或卸载第三方库时报You are using pip version 9.0.3, however version 18.0 is available.错误,一般情况下是pip版本过 ...
- 数据分析—NaN数据处理
目的 1.查找NaN值(定位到哪一列.在列的哪个索引位置) 2.填充NaN值(向上填充.向下填充.线性填充等) 3.过滤NaN值 构建简单的Dataframe数据结构环境 import pandas ...
- mssql发布订阅事项
在发布订阅过程中遇到2个需求: 1.在原有的发布快照中增加发布内容,追加模式需要在追加的表中设计一个主键,要不然没有办法进行发布的,另外还得注意将这两个字段进行更改: select immediate ...
- c++ devived object model
单一虚函数继承 class A{public: virtual int foo( ) { return val ; } virtual int funA( ) {}private: int val ; ...
- MIFARE Classic S50技术详解
Mifare Classic 简介 MIFARE Classic是恩智浦半导体开发的可用于非接触式智能卡,符合ISO/IEC 14443 A类标准.用于公共交通票证等应用,还可用于各类其他应用有S20 ...
- Redux & React & react-redux
Redux Redux & React & react-redux https://redux.js.org/ https://redux.js.org/api https://red ...
- 前端构建工具gulpjs的使用介绍及技巧 (转)
gulpjs是一个前端构建工具,与gruntjs相比,gulpjs无需写一大堆繁杂的配置参数,API也非常简单,学习起来很容易,而且gulpjs使用的是nodejs中stream来读取和操作数据,其速 ...
- LeetCode -- Implement Stacks using Queue
Question: Implement the following operations of a queue using stacks. push(x) -- Push element x to t ...
- Educational Codeforces Round 22 E. Army Creation
Educational Codeforces Round 22 E. Army Creation 题意:求区间[L,R]内数字次数不超过k次的这些数字的数量的和 思路:和求区间内不同数字的数量类似,由 ...
- HDU 5761 物理题
Rower Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...