【poj 1269】Intersecting Lines

http://poj.org/problem?id=1269


真是个令人忧桑的故事。。。


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep(i,l,r) for(int i=(l),_=(r);i<=_;i++)
#define per(i,r,l) for(int i=(r),_=(l);i>=_;i--)
#define MS(arr,x) memset(arr,x,sizeof(arr))
#define INE(i,u) for(int i=head[u];~i;i=e[i].next)
#define LL long long
#define Vector Point
#define data pair<Point,int>
inline const int read()
{int r=0,k=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;
for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;}

const double eps=1e-8;
double dcmp(double x){if(fabs(x)<eps)return 0;return x>0?1:-1;}
struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
	Point operator+(const Point &b)const{return Point(x+b.x,y+b.y);}
	Vector operator-(const Point &b)const{return Point(x-b.x,y-b.y);}
	Point operator*(const double &b)const{return Point(x*b,y*b);}
	double operator^(Point b)const{return x*b.y-y*b.x;}
};
struct Line{
	Point p,v;
	Line(){}
	Line(Point p,Vector v):p(p),v(v){}
	data operator&(Line &b)
	{
		double x=v^b.v,y=b.v^p-b.p;
		if(!x)
		{
			if(y) return (data){p,-1};
			else return (data){p,1};
		}
		return (data){p+v*(y/x),0};
	}
};
struct Seg{
	Point s,t;
}a,b;



void input()
{
    scanf("%lf%lf%lf%lf",&a.s.x,&a.s.y,&a.t.x,&a.t.y);
    scanf("%lf%lf%lf%lf",&b.s.x,&b.s.y,&b.t.x,&b.t.y);
}
void solve()
{
	Line la=Line(a.s,a.t-a.s);
	Line lb=Line(b.s,b.t-b.s);
	pair<Point,int> ret=la&lb;
	if(ret.second==-1) puts("NONE");
	else if(ret.second==1) puts("LINE");
	else printf("POINT %.2f %.2f\n",ret.first.x,ret.first.y);
}

int main()
{
    //freopen("_.in","r",stdin); freopen("_.out","w",stdout);
    puts("INTERSECTING LINES OUTPUT");
    rep(i,1,read())
    input(),solve();
    puts("END OF OUTPUT");
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值