极角排序——ICPC Latin American Regional Contests 2019 D
Posted zsben991126
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了极角排序——ICPC Latin American Regional Contests 2019 D相关的知识,希望对你有一定的参考价值。
这题还是按角度进行极角排序简单点
/* 按亮度从大到小排序,从大的给小的连一条向量,极角排序后所有向量在两个象限内,那么可行,反之不可行 */ #include<bits/stdc++.h> using namespace std; #define N 1005 typedef double db; const db eps=1e-8; const db pi=acos(-1); int sign(db k){ if (k>eps) return 1; else if (k<-eps) return -1; return 0; } int cmp(db k1,db k2){return sign(k1-k2);} int inmid(db k1,db k2,db k3){return sign(k1-k3)*sign(k2-k3)<=0;}// k3 在 [k1,k2] 内 struct point{ db x,y,rad; point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};} point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};} point operator * (db k1) const{return (point){x*k1,y*k1};} point operator / (db k1) const{return (point){x/k1,y/k1};} int operator == (const point &k1) const{return cmp(x,k1.x)==0&&cmp(y,k1.y)==0;} point turn(db k1){return (point){x*cos(k1)-y*sin(k1),x*sin(k1)+y*cos(k1)};} point turn90(){return (point){-y,x};} bool operator < (const point k1) const{ int a=cmp(x,k1.x); if (a==-1) return 1; else if (a==1) return 0; else return cmp(y,k1.y)==-1; } db abs(){return sqrt(x*x+y*y);} db abs2(){return x*x+y*y;} db dis(point k1){return ((*this)-k1).abs();} db getw(){return atan2(y,x);} point getdel(){if (sign(x)==-1||(sign(x)==0&&sign(y)==-1)) return (*this)*(-1); else return (*this);} int getP() const{return sign(y)==1||(sign(y)==0&&sign(x)>=0);} }; int inmid(point k1,point k2,point k3){return inmid(k1.x,k2.x,k3.x)&&inmid(k1.y,k2.y,k3.y);} db cross(point k1,point k2){return k1.x*k2.y-k1.y*k2.x;} db dot(point k1,point k2){return k1.x*k2.x+k1.y*k2.y;} int comp(point k1,point k2){ return k1.rad<k2.rad; } point v[N*N],k1,k2; int n,tot; struct Node{ int x,y,w; }p[N]; int cmp1(Node a,Node b){return a.w>b.w;} db rads[N]; int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>p[i].x>>p[i].y>>p[i].w; sort(p+1,p+1+n,cmp1); for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) if(p[i].w>p[j].w)v[++tot]=(point){1.0*p[j].x-p[i].x,1.0*p[j].y-p[i].y}; for(int i=1;i<=tot;i++) v[i].rad=atan2(v[i].y,v[i].x); sort(v+1,v+1+tot,comp);//极角排序 if(tot<=2){ puts("Y");return 0; } //判断是否所有向量都在两个象限内 int flag=0; for(int i=2;i<=tot;i++){ db rad1=v[i-1].rad; db rad2=v[i].rad; if(sign(rad2-rad1-pi)>=0) flag=1; } db rad1=v[tot].rad; db rad2=v[1].rad; if(rad2>rads[2])rad2-=2*pi; if(sign(rad1-rad2-pi)<=0) flag=1; if(flag)puts("Y"); else puts("N"); } /* 8 -9 -1 3 -3 -10 1 8 -9 1 1 7 2 -8 -5 2 1 -4 2 2 -8 3 6 -4 3 */
以上是关于极角排序——ICPC Latin American Regional Contests 2019 D的主要内容,如果未能解决你的问题,请参考以下文章
2019.09.21ICPC Latin American Regional-2017
计算几何——ICPC Latin American Regional Contests 2019 B
训练20191007 2017-2018 ACM-ICPC Latin American Regional Programming Contest
2017-2018 ACM-ICPC Latin American Regional Programming Contest
2019-2020 ACM-ICPC Latin American Regional Programming Contest L - Leverage MDT
2017-2018 ACM-ICPC Latin American Regional Programming Contest GYM101889