POJ1269 直线相交

版子 http://blog.csdn.net/acm_zl/article/details/9471451

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <string.h>
    #include <map>
    #include <vector>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <stack>
    using namespace std;  

    int main()
    {
        int t;
        double x1,y1,x2,y2,x3,y3,x4,y4;
        scanf("%d", &t);
        printf("INTERSECTING LINES OUTPUT\n");
        while(t--)
        {
            scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
            if(x1==x2 && x3==x4)//两直线都没有斜率
            {
                if(x3==x1)
                    printf("LINE\n");
                else
                    printf("NONE\n");
            }
            else if(x1==x2 && x3!=x4)//有一条直线斜率存在
            {
                double k = (y4-y3)*1.0/(x4-x3);
                double b = y3-(k*x3);
                double ansx = x1;
                double ansy = k*x1+b;
                printf("POINT %.2lf %.2lf\n", ansx, ansy);
            }
            else if(x1!=x2 && x3==x4)//有一条直线斜率存在
            {
                double k = (y2-y1)*1.0/(x2-x1);
                double b = y2-(k*x2);
                double ansx = x3;
                double ansy = k*x3+b;
                printf("POINT %.2lf %.2lf\n", ansx, ansy);
            }
            else //两条直线斜率都存在
            {
                double k1 = (y2-y1)*1.0/(x2-x1);
                double b1 = y2-(k1*x2);
                double k2 = (y4-y3)*1.0/(x4-x3);
                double b2 = y3-(k2*x3);
                if(k1==k2)
                {
                    if(b1==b2)
                        printf("LINE\n");
                    else
                        printf("NONE\n");
                }
                else
                {
                    double ansx = (b1-b2)*1.0/(k2-k1);
                    double ansy = k1*ansx + b1;
                    printf("POINT %.2lf %.2lf\n", ansx, ansy);
                }
            }
        }
        printf("END OF OUTPUT\n");
        return 0;
    }  
时间: 2024-10-08 18:41:45

POJ1269 直线相交的相关文章

直线与直线相交 直线与线段相交 线段与线段相交

int sgn(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); } //叉积 double opera

判断线段和直线相交 POJ 3304

1 // 判断线段和直线相交 POJ 3304 2 // 思路: 3 // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. 4 5 #include <cstdio> 6 #include <cstring> 7 #include <iostream> 8 #include <algorithm> 9 #include <map> 10 #include <set> 11 #inclu

poj2074Line of Sight(直线相交)

链接 几何细节题. 对于每一个障碍物可以求出它在地产线上的覆盖区间,如下图. 紫色部分即为每个障碍物所覆盖掉的区间,求出所有的,扫描一遍即可. 几个需要注意的地方:直线可能与地产线没有交点,可视区间可能包含地产线的端点,扫描的时候保留当前扫到的最大值. 代码中的数据很经典,供参考. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #inc

poj 1127(直线相交+并查集)

Jack Straws Description In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table and players try to remove them one-by-one without disturbing the other straws. Here, we are only concerned with if various pairs o

Jack Straws(并差集和判断直线相交问题)

Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3155   Accepted: 1418 Description In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table and players try to remove them one-by-one witho

POJ 1269 Intersecting Lines(判断直线相交)

题目地址:POJ 1269 直接套模板就可以了...实在不想自己写模板了...写的又臭又长....不过这题需要注意的是要先判断是否有直线垂直X轴的情况. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h>

UVA_11178_Morley&#39;s_Theorem_(向量旋转+直线相交)

描述 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=23&page=show_problem&problem=2119 Morley定理:作三角形ABC每个内角的三等分线,相交形成三角形DEF,则三角形DEF是等边三角形. 给出三角形的三个顶点ABC的坐标,求出DEF的坐标. 11178 - Morley's Theorem Time limit: 3.000 s

poj 1556 zoj1721 BellmanFord 最短路+判断直线相交

http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6120   Accepted: 2455 Description You are to find the length of the shortest path through a chamber containing obstructing walls. The chamber will a

直线相交 POJ 1269

1 // 直线相交 POJ 1269 2 3 // #include <bits/stdc++.h> 4 #include <iostream> 5 #include <cstdio> 6 #include <cstdlib> 7 #include <algorithm> 8 #include <math.h> 9 using namespace std; 10 #define LL long long 11 typedef pair