极角排序——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

*/

原文地址:https://www.cnblogs.com/zsben991126/p/12670249.html

时间: 2024-11-07 21:38:24

极角排序——ICPC Latin American Regional Contests 2019 D的相关文章

训练20191007 2017-2018 ACM-ICPC Latin American Regional Programming Contest

2017-2018 ACM-ICPC Latin American Regional Programming Contest 试题地址:http://codeforces.com/gym/101889 总体情况 总共通过7题CEFGHIJ.其中我完成HIJ三题.纯属被大佬带飞系列. 解题报告 H - Hard choice 签到题 #include <bits/stdc++.h> using namespace std; int a1,b1,c1,a2,b2,c2; int main() {

【2019.09.21】ICPC Latin American Regional-2017

提交地址:https://codeforces.com/gym/101889 解题数:6/13 题目: A: B: C: D: E: F: G: H: I: J: K: L: M: 感觉整场下来自己的贡献很低,A题看了题解是道比较综合的算法题,不只包含计算几何的内容,防ak的,暂不补.计算几何学了皮毛大概能做出中档题的时候就要收手去学其他模块的题了,加快学习进度.(zkq) 原文地址:https://www.cnblogs.com/ncu2019/p/11565382.html

2017-2018 ACM-ICPC Latin American Regional Programming Contest Solution

A - Arranging tiles 留坑. B - Buggy ICPC 题意:给出一个字符串,然后有两条规则,如果打出一个辅音字母,直接接在原字符串后面,如果打出一个元音字母,那么接在原来的字符串后面之后再翻转整个字符串,在这两条规则之下,求有多少种打印给定字符串的方法 思路:如果第一个字符是辅音,那么答案为0 如果全是辅音或全是元音,那么答案为1 如果只有一个辅音,答案为len 否则是最中间两个元音中间的辅音字符个数+1 1 #include <bits/stdc++.h> 2 3 u

2017-2018 ACM-ICPC Latin American Regional Programming Contest

题面pdfhttps://codeforc.es/gym/101889/attachments/download/7471/statements-2017-latam-regional.pdf zyn感冒,两个人打.刚开始两题超迅速,40分钟后开始各种写不出,自闭.然后突然又开出两题. 4题全部1A,70名左右应该能稳个银. 说明卡题了可千万不能放弃!虽然可能简单题做不出来,过的多的题目做不出来,也不要放弃去开题. 以及周末这两场都说明一定要胆子大. B---Buggy ICPC[找规律] 题意

2017-2018 ACM-ICPC Latin American Regional Programming Contest GYM101889

挺有意思的一套题,题也没有啥毒瘤了,本来是队切的结果种种原因大家全挂机了. 只补了百人题,一共7个,其他的暂时先不补了,,也不会嘛qwq H:签到 1 #include <bits/stdc++.h> 2 using namespace std; 3 int a[18],b[18]; 4 int main(){ 5 cin>>a[1]>>a[2]>>a[3]>>b[1]>>b[2]>>b[3]; 6 int ans = 0

2019-2020 ACM-ICPC Latin American Regional Programming Contest A- Algorithm Teaching 二分图

#include<bits/stdc++.h> #define f first #define s second using namespace std; typedef long long ll; const int N=300005; typedef pair<int,int> P; int n,tot,t,V; map<string,int> mp; map<vector<int>,int> mp2; vector<int> G

2019-2020 ACM-ICPC Latin American Regional Programming Contest L - Leverage MDT

#include<map> #include<queue> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define LL long long const int N=1010; int val[N][N]; int res[N][N]; char c[N][N]; int n,m; bo

2019-2020 ACM-ICPC Latin American Regional Programming Contest I - Improve SPAM 树形dp?

#include<iostream> #include<cstring> #define int long long using namespace std; const int N=4010,mod=1e9+7; int a[N]; int e[N*N],ne[N*N],idx,h[N]; int st[N]; int ans; int ans1[N]; int read() { int res=0,ch,flag=0; if((ch=getchar())=='-') //判断正

HDU Always Cook Mushroom (极角排序+树状数组)

Problem Description Matt has a company, Always Cook Mushroom (ACM), which produces high-quality mushrooms. ACM has a large field to grow their mushrooms. The field can be considered as a 1000 * 1000 grid where mushrooms are grown in grid points numbe