poj1254Hansel and Grethel poj1269Intersecting_Lines

poj1254Hansel and Grethel

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps=1e-10;
const double pi=acos(-1.0);
const int inf=1e8;
inline int dcmp(double x){
    if(x < eps) return 0;
    return x>0?1:-1;
}
struct pt{
    double x,y;
    pt(){}
    pt(int xx,int yy):x(xx),y(yy){}
    friend pt operator - (pt a,pt b){
        return pt(a.x-b.x,a.y-b.y);
    }
};
inline double cross(pt a,pt b){
    return a.x*b.y-a.y*b.x;
}

inline void intersect_line(pt a,pt b,pt c,pt d){
    //cout<<cross(a-b,c-d)<<endl;
    double t=cross(a-c,c-d)/cross(a-b,c-d);
    //cout<<t<<endl;
    //cout<<a.x+(b.x-a.x)*t<<endl;
    printf("%.4f %.4f\n",(a.x+(b.x-a.x)*t),(a.y+(b.y-a.y)*t));
}
inline int xulv(int k){
    if(k>0 && k<=90) return (90-k);
    if(k>90 && k<270)return (270-k);
    if(k>=270 && k<360)return (450-k);
}
int main(){
    int T,d[2];
    pt p[4];
    cin>>T;
    while(T--){
        for(int i=0;i<2;i++)
            scanf("%lf%lf%d",&p[i].x,&p[i].y,&d[i]);
        if(d[0]==0 ||d[0]==360){
                p[2].y=p[0].y+10.0;
                p[2].x=p[0].x;
        }
        else{
            int k=xulv(d[0]);
            p[2].x=p[0].x+inf*cos(k*pi/180);
            p[2].y=p[0].y+inf*sin(k*pi/180);
        }
        if(d[1]==0 ||d[1]==360){
                p[3].x=p[1].x;
                p[3].y=p[1].y+10.0;
        }
        else{
            int k=xulv(d[1]);
            p[3].x=p[1].x+inf*cos(k*pi/180);
            p[3].y=p[1].y+inf*sin(k*pi/180);
        }
        //for(int i=0;i<4;i++)
            //printf("%lf %lf\n",p[i].x,p[i].y);
        intersect_line(p[0],p[2],p[1],p[3]);
    }
    return 0;
}
poj1269Intersecting_Lines

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const double eps=1e-10;
inline int dcmp(int x){
    if(!x) return 0;
    return x>0?1:-1;
}
struct pt{
    int x,y;
    pt(){}
    pt(int xx,int yy):x(xx),y(yy){}
    friend pt operator -(pt a,pt b){
        return pt(a.x-b.x,a.y-b.y);
    }
};
inline int cross(pt a,pt b){
    return a.x*b.y-a.y*b.x;
}
void intersect_line(pt a,pt b,pt c,pt d){
    if(dcmp(cross(a-b,c-d))==0){
        if(!dcmp(cross(c-a,d-a))) {
            cout<<"LINE"<<endl;
            return ;
        }
        else{
           cout<<"NONE"<<endl;
           return;
        }
    }
    double t=cross(a-c,c-d)*1.0/cross(a-b,c-d);
    //cout<<'a'<<t<<endl;
    double x=a.x,y=a.y;
    x+=(double)(b.x-a.x)*t;
    y+=(double)(b.y-a.y)*t;
    //cout<<ret.x<<' '<<ret.y<<endl;
    printf("POINT %.2lf %.2lf\n",x,y);
}
int main(){
    int T,i;
    cin>>T;
    cout<<"INTERSECTING LINES OUTPUT"<<endl;
    while(T--){
        pt p[4];
        for(i=0;i<4;i++){
            scanf("%d%d",&p[i].x,&p[i].y);
        }
        intersect_line(p[0],p[1],p[2],p[3]);
        //if(tmp.second==0)cout<<"LINE"<<endl;
        //else if(tmp.second==1)cout<<"NONE"<<endl;
        //else{
          //  cout<<"POINT "<<tmp.first.x<<' '<<tmp.first.y<<endl;
        //}
    }
    cout<<"END OF OUTPUT"<<endl;
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值