POJ 1269 Intersecting Lines G++ 分别给出两条直线上的两点求直线关系 背

#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
//英语      看博友分析      抄博友程序     分别给出两条直线上的两点求直线关系     背 
int main()
{
	int T;
	cin>>T;
	cout<<"INTERSECTING LINES OUTPUT"<<endl;
	while(T--)
	{
		double x1,y1,x2,y2,x3,y3,x4,y4;
		cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
		if(x1==x2 && x3==x4)
		{
			if(x1==x3)
			{
				cout<<"LINE"<<endl;
			}else
			{
				cout<<"NONE"<<endl;
			} 
		}else if(x1==x2)
		{
			double k=(y3-y4)/(x3-x4);
			double b=y3-k*x3;
			cout<<"POINT ";
			cout<<fixed<<setprecision(2)<<x1<<" "<<k*x1+b<<endl;
		}else if(x3==x4)
		{
			double k=(y1-y2)/(x1-x2);
			double b=y1-k*x1;
			cout<<"POINT ";
			cout<<fixed<<setprecision(2)<<x3<<" "<<k*x3+b<<endl;			
		}else
		{
			double k1=(y1-y2)/(x1-x2);
			double b1=y1-k1*x1;
			double k2=(y3-y4)/(x3-x4);
			double b2=y3-k2*x3;
			if(k1==k2 && b1==b2)
			{
				cout<<"LINE"<<endl;
			}else if(k1==k2)
			{
				cout<<"NONE"<<endl;
			}else
			{
				double x=(b2-b1)/(k1-k2);
				cout<<"POINT ";
				cout<<fixed<<setprecision(2)<<x<<" "<<k1*x+b1<<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、付费专栏及课程。

余额充值