首页 > 其他分享 >Codeforces 1446F - Line Distance

Codeforces 1446F - Line Distance

时间:2023-07-20 12:22:33浏览次数:40  
标签:Distance begin int double pb vec key Line 1446F

感觉这种类似于让你找第 \(k\) 大距离的计算几何题其实都挺套路的。

二分一个答案 \(t\),然后思考一下什么样的点对满足原点到它们的连线的距离 \(\le t\)。以原点为圆心 \(t\) 为半径画个圆,然后分情况讨论:

  • 如果 \((x_i,y_i)\) 或 \((x_j,y_j)\) 在圆内,那么必然符合条件。
  • 如果 \((x_i,y_i)\) 和 \((x_j,y_j)\) 都在圆外,那么考虑做这两个点到圆的切线,那么我们惊奇地发现,原点到这两点连线的距离 \(\le t\),当且仅当这两点对应的两条切线的辐角组成的区间只有相交和包含关系。

于是就做完了,离散化一下然后树状数组做即可。注意由于包含和无交都合法,因此如果 \(l>r\) 直接交换 \(l,r\) 即可,不用拆成 \([l,2\pi]\) 和 \([0,r]\) 两个区间。

时间复杂度 \(n\log n\log V\)。

const int MAXN=1e5;
const double EPS=1e-9;
const double Pi=acos(-1);
int n;ll k;
int sgn(double x){return ((x<-EPS)?-1:((x<EPS)?0:1));}
struct point{
	double x,y;
	point(){x=y=0;}
	point(double _x,double _y){x=_x;y=_y;}
	friend point operator+(const point &X,const point &Y){return point(X.x+Y.x,X.y+Y.y);}
	friend point operator-(const point &X,const point &Y){return point(X.x-Y.x,X.y-Y.y);}
	friend point operator*(const point &X,const double &Y){return point(X.x*Y,X.y*Y);}
	friend double operator |(const point &X,const point &Y){return X.x*Y.y-X.y*Y.x;}
	friend double operator ^(const point &X,const point &Y){return X.x*Y.x+X.y*Y.y;}
	friend bool operator ==(const point &X,const point &Y){return sgn(X.x-Y.x)==0&&sgn(X.y-Y.y)==0;}
	friend bool operator !=(const point &X,const point &Y){return sgn(X.x-Y.x)!=0||sgn(X.y-Y.y)!=0;}
	double operator ~()const{return sqrt(x*x+y*y);}
	double operator !()const{return atan2(y,x);}
}p[MAXN+5];
void norm(double &d){
	while(d<-EPS)d+=2*Pi;
	while(d>2*Pi-EPS)d-=2*Pi;
}
int t[MAXN*5+5];
void add(int x,int v){for(int i=x;i<=MAXN*5;i+=(i&(-i)))t[i]+=v;}
int query(int x){int ret=0;for(int i=x;i;i&=(i-1))ret+=t[i];return ret;}
ll calc(double d){
	ll res=0;
	vector<pair<double,double> >vec;
	vector<pii>nvec;vector<double>key;
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(~p[i]<(d+EPS));
		else{
			double ang=acos(d/(~p[i]));
			double l=(!p[i])-ang,r=(!p[i])+ang;
			norm(l);norm(r);
			if(l>r)swap(l,r);
			vec.pb(mp(l,r));
		}
	}
	res=1ll*n*(n-1)/2;
	for(pair<double,double>p:vec)key.pb(p.fi),key.pb(p.se);
	sort(key.begin(),key.end());
	for(pair<double,double>p:vec){
		int L=lower_bound(key.begin(),key.end(),p.fi)-key.begin();
		int R=lower_bound(key.begin(),key.end(),p.se)-key.begin();
		nvec.pb(mp(L+1,R+1));
	}
	memset(t,0,sizeof(t));
	sort(nvec.begin(),nvec.end());
	for(int i=0;i<nvec.size();i++){
		int l=nvec[i].fi,r=nvec[i].se;
		res-=query(r)-query(l-1);add(r,1);
	}
	return res;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
//	calc(0.8);
	double l=EPS,r=20000,p=0;
	while(fabs(r-l)>EPS){
		double mid=(l+r)/2;
		if(calc(mid)>=k)p=r=mid;
		else l=mid;
	}printf("%.10lf\n",p);
	return 0;
}

标签:Distance,begin,int,double,pb,vec,key,Line,1446F
From: https://www.cnblogs.com/tzcwk/p/Codeforces-1446F.html

相关文章

  • linux 中 awk命令中 getline的用法
     001、[root@PC1test02]#ls[root@PC1test02]#seq1012345678910[root@PC1test02]#seq10|awk'{getline;print$0}'##getline把两行当作一行处理,而且跳过了第一行246810 002、[root@PC1test02]#ls[root@PC1test02]#seq1012345......
  • linux 中awk命令getline函数实现从内部读取文件内容
     001、[root@PC1test02]#lsa.txtb.txt[root@PC1test02]#cata.txt##测试数据123456[root@PC1test02]#catb.txt##测试数据111213141516[root@PC1test02]#awk'{printf"%s",$0;getline<"b.txt";p......
  • linux awk 命令中 next 和 getline
     001、continue[root@PC1test01]#lsdata[root@PC1test01]#catdata##测试数据1000naughty500cc400zoer100[root@PC1test01]#awk'{if(NR==2){next};print$0}'data##next相当于内层循环的continue,表示跳过该次迭代1000cc400zoer100......
  • 声明式pipeline docker镜像构建推送
    实现声明式PipelineDocker镜像构建推送作为一名经验丰富的开发者,你需要教会一位刚入行的小白如何实现“声明式PipelineDocker镜像构建推送”。下面将详细介绍整个流程以及每一步需要做的事情,包括所需的代码和代码的注释。流程概述声明式Pipeline是一种用于定义Jenkins任务的方......
  • android transaction failed 29201/-1, size 0-0 line 3009
    解决"androidtransactionfailed29201/-1,size0-0line3009"错误引言在Android开发中,我们经常会遇到各种错误和异常。其中一个常见的错误是"androidtransactionfailed29201/-1,size0-0line3009"。这个错误通常与Fragment事务相关,并且可能会导致应用崩溃或功能异常......
  • IDEA 启动报错:Error running 'DemoApplication': Command line is too long. Shorten
     IDEA启动报错:Errorrunning'DemoApplication':Commandlineistoolong.ShortencommandlineforDemoApplicationoralsoforSpringBootdefaultconfiguration. 修改 打开 修改成  然后在重新启动即可......
  • [论文笔记] Line-CNN: End-to-End Traffic Line Detection With Line Proposal Unit
    IEEETITS2019YangJianlastupdate:2023/07/17简介作者受Faster-RCNN启发,提出Line-CNN,提出了一种新颖的车道线Anchor的表示方法,解决了车道线检测中表征的难点,实现了端到端的车道线检测.车道线是一条曲线,所以无法使用常规检测中矩形bbox作为Anchor,为了用Anchor来......
  • hive kerberos beeline 指定用户名
    使用HiveKerberosBeeline指定用户名的流程在这篇文章中,我将向你解释如何使用HiveKerberosBeeline指定用户名的流程。我们将使用一些必要的代码来完成这个任务。整体流程下面是使用HiveKerberosBeeline指定用户名的整体流程,我们将使用以下步骤来实现。步骤描述1.......
  • Baseline实验环境准备
    实验Baseline环境搭建准备为了尽快地写成论文初稿,首先需要把实验完成。先将待做实验按几个方面分类:数据集GLUE数据集任务SST模型TransformerBert评价指标BLEUBERTSimilarityBitRate对于GLUE数据集以及其对应的相关任务,我还有点懵逼,在网上也找不到Tra......
  • Scrapy在pipeline中集成mongodb
    settings.py中设置配置项MONGODB_HOST="127.0.0.1"MONGODB_PORT=27017MONGODB_DB_NAME="bang123"pipelines.py:fromscrapy.pipelines.imagesimportImagesPipelinefromitemadapterimportis_item,ItemAdapterclassBang123Pipeline:......