Intersecting Lines

题目链接:https://vjudge.net/problem/POJ-1269

题意:给你两条直线,让你判断直线的位置关系(平行,重合,相交)。如果是相交的话要把交点求出来。

思路:直接用差积来判断位置关系即可。对于交点也可以用差积求出。就是用G++题交会wa,用c++提交就可以过

//#include <bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const double eps=1e-10;
int chaj(int x1,int y1,int x2,int y2)
{
    return x1*y2-x2*y1;
}
int main()
{
    int t;
    cin>>t;
    cout<<"INTERSECTING LINES OUTPUT"<<endl;
    while(t--)
    {
        int x1,y1,x2,y2,x3,y3,x4,y4;
        cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
        if((y2-y1)*(x4-x3)==(y4-y3)*(x2-x1))
        {
            if(chaj(x2-x1,y2-y1,x3-x1,y3-y1)==0)
                cout<<"LINE"<<endl;
            else
                cout<<"NONE"<<endl;
            continue;
        }
        cout<<"POINT ";
        double w=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
        double len=sqrt(w);
        double s1=abs(chaj(x3-x1,y3-y1,x4-x1,y4-y1));
        double s2=abs(chaj(x3-x2,y3-y2,x4-x2,y4-y2));
        double len1=s1/(s1+s2);
        double x=len1*(x2-x1),y=len1*(y2-y1);
        x=x+x1;y=y+y1;
        printf("%.2lf %.2lf\n",x,y);
    }
    cout<<"END OF OUTPUT"<<endl;
}

 

posted @ 2020-09-13 20:37  ~zcb  阅读(101)  评论(0编辑  收藏  举报