ICPC昆明站 I.Mr. Main and Windmills

  • 思路
    把每个点和其他的一些点的连线和已知的S-T线段的交点存起来,然后按照距离S点的远近排序。
    比赛的时候敲错了一个模板,也怨自己还不是太熟悉计算几何的原理吧。。。
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;

struct Point{
    double x,y;
    double dis;
    Point(double x=0,double y=0):x(x),y(y){}
};

typedef Point Vector;

Vector operator + (Vector A,Vector B) {
    return Vector(A.x+B.x,A.y+B.y);
}
Vector operator - (Vector A,Vector B) {
    return Vector(A.x-B.x,A.y-B.y);
}
Vector operator * (Vector A,double p) {
    return Vector(A.x*p,A.y*p);
}

Vector operator / (Vector A,double p) {
    return Vector(A.x/p,A.y/p);
}
bool operator < (const Point &a,const Point &b){
    return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
const double eps=1e-10;

int dcmp(double x){
    if(fabs(x)<eps){
        return 0;
    }
    else return x<0?-1:1;
}

bool operator ==(const Point& a,const Point &b){
    return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;
}

double Dot(Vector A,Vector B){
    return A.x*B.x+A.y*B.y;
}

double Length(Vector A){
    return sqrt(Dot(A,A));
}

double Angle(Vector A,Vector B) {
    return acos(Dot(A,B)/Length(A)/Length(B));
}

double Cross(Vector A,Vector B){
    return A.x*B.y-A.y*B.x;
}
Vector Rotate(Vector A,double rad){
    return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*(rad));
}

Point GetLineIntersection(Point P,Vector v,Vector Q,Vector w){
    Vector u=P-Q;
    double t=Cross(w,u)/Cross(v,w);
    return P+v*t;
}

bool SegmentProperInterSection(Point a1,Point a2,Point b1,Point b2){
    double c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1);
    double c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
    return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0;
}

bool OnSegment(Point p,Point a1,Point a2){
    return dcmp(Dot(a1-p,a2-p))<=0;
}

double length(Point &a,Point &b){
    return sqrt(pow(fabs(a.x-b.x),2)+pow(fabs(a.y-b.y),2));
}
struct node
{
    Point p;
    vector<Point> Node;
}a[N];
bool cmp(Point a,Point b){
    return a.dis<b.dis;
}

int main()
{
    int n,m;
    cin>>n>>m;
    Point S,T;
    cin>>S.x>>S.y>>T.x>>T.y;
    for(int i=1;i<=n;i++){
        cin>>a[i].p.x>>a[i].p.y;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(i==j){
                continue;
            }
            Point temp;
            Point P=a[i].p;
            Vector v=a[i].p-a[j].p;
            Vector w=S-T;
            temp=GetLineIntersection(P,v,S,w);
            temp.dis=length(temp,S);
            if(OnSegment(temp,S,T)){
                a[i].Node.push_back(temp);
            }
        }
    }
    while(m--){
        int h,k;
        cin>>h>>k;
        if(a[h].Node.size()<k){
            cout<<-1<<endl;
        }
        else{
            sort(a[h].Node.begin(),a[h].Node.end(),cmp);
            Point X=a[h].Node[k-1];
            printf("%.10f %.10f\n",X.x,X.y);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疯狂的码泰君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值