A - Area 51 Gym - 101334A 计算几何 极坐标 poj 1696 极坐标排序

该博客介绍了一道计算几何题目,涉及到极坐标排序的应用。题目要求根据给定的第一和第二象限的点,找出从x轴的哪些区间观察时,点的顺序符合特定序列。解决方案包括对点进行极坐标排序,并在处理区间时避免重复排序,只需在遇到分割点时调整序列。
摘要由CSDN通过智能技术生成

题意


给定n个位于第一和第二象限的点,每一个点都有一个符号表示

给出一个序列,问从x轴的哪些区间从做往右看刚好符合这个序列


题解:

输入后进行极坐标排序,以负无穷为源点,按角的大小降序排列,若有相同角的就按照近的在前

再计算区间的分割点

然后枚举区间,看是否符合题意


这里不需要在枚举区间的时候都进行极坐标排序,只需要经过一个区间分割点的时候将两个字母换一个位置即可



#include<vector>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

vector<pair<double,double> >ans;

#define MAXN 110
#define inf 0x3f3f3f3f
const double eps=1e-8;
char str[MAXN];
int now[MAXN*MAXN];
struct Point
{
    char ch[5];
    double x,y;
    Point(){}
    Point(double _X, double _Y){
        x = _X; y = _Y;
    }
};
Point P[MAXN];
struct Line
{
    double x;
    int t1,t2;
    Line(){}
    Line(double _x,int _t1,int _t2){
        x=_x,t1=_t1,t2=_t2;
    }
};
Line line[MAXN*MAXN];

double Cross(Point p1,Point p2,Point p3){
    return (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x);
}
double Dis(Point A, Point B){
    return sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));
}
Point operator - (Point A,Point B){
    return Point(A.x-B.x, A.y-B.y);
}
Point operator + (Point A, Point B){
    return Point(A.x+B.x, A.y+B.y);
}
Point operator * (Point A, double p){
    return Point(A.x*p, A.y*p);
}
bool operator == (Point A, Point B){
    return (A.x-B.x) == 0 && (A.y-B.y) == 0;
}
int sgn(double x)
{
    if(fabs(x)<eps)
        return 0;
    if(x<0)
        return -1;
    return 1;
}

bool cmp(Point a, Point b)///按极角降序排序,若角度相等距离小的在前面
{
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值