zoukankan      html  css  js  c++  java
  • poj 1269 Intersecting Lines (计算几何)

    Intersecting Lines
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 12863   Accepted: 5712

    Description

    We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one another (i.e. they are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect. 
    Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000. 

    Input

    The first line contains an integer N between 1 and 10 describing how many pairs of lines are represented. The next N lines will each contain eight integers. These integers represent the coordinates of four points on the plane in the order x1y1x2y2x3y3x4y4. Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).

    Output

    There should be N+2 lines of output. The first line of output should read INTERSECTING LINES OUTPUT. There will then be one line of output for each pair of planar lines represented by a line of input, describing how the lines intersect: none, line, or point. If the intersection is a point then your program should output the x and y coordinates of the point, correct to two decimal places. The final line of output should read "END OF OUTPUT".

    Sample Input

    5
    0 0 4 4 0 4 4 0
    5 0 7 6 1 0 2 3
    5 0 7 6 3 -6 4 -3
    2 0 2 27 1 5 18 5
    0 3 4 0 1 2 2 5
    

    Sample Output

    INTERSECTING LINES OUTPUT
    POINT 2.00 2.00
    NONE
    LINE
    POINT 2.00 5.00
    POINT 1.07 2.20
    END OF OUTPUT
    

     给出n对直线。。。问每对直线的位置关系(平行,重合,相交,相交的话要求出交点)

    嗯。

      1 /*************************************************************************
      2     > File Name: a.cpp
      3     > Author: 111qqz
      4     > Email: rkz2013@126.com 
      5     > Created Time: 2015年11月06日 星期五 09时48分39秒
      6  ************************************************************************/
      7 
      8 #include<iostream>
      9 #include<iomanip>
     10 #include<cstdio>
     11 #include<algorithm>
     12 #include<cmath>
     13 #include<cstring>
     14 #include<string>
     15 #include<map>
     16 #include<set>
     17 #include<queue>
     18 #include<vector>
     19 #include<stack>
     20 #include<cctype>
     21 #define fst first              
     22 #define lson l,m,rt<<1
     23 #define rson m+1,r,rt<<1|1
     24 #define ms(a,x) memset(a,x,sizeof(a))
     25 using namespace std;
     26 const int dx4[4]={1,0,0,-1};
     27 const int dy4[4]={0,-1,1,0};
     28 typedef long long LL;
     29 #define sec second
     30 const int inf = 0x3f3f3f3f;
     31 const double eps=1E-8;
     32 int n;
     33 
     34 int dblcmp( double d)
     35 {
     36     return d<-eps?-1:d>eps;
     37 }
     38 
     39 struct  point
     40 {
     41     double x,y;
     42     point(){}
     43     point(double _x,double _y):
     44     x(_x),y(_y){};
     45     void input() 
     46     {
     47     scanf("%lf%lf",&x,&y);
     48     }
     49     void output()
     50     {
     51     printf("%.2f %.2f
    ",x,y);
     52     }
     53     point sub(point p)
     54     {
     55     return point(x-p.x,y-p.y);
     56     }
     57     double det(point p)
     58     {
     59     return x*p.y-y*p.x;
     60     }
     61 
     62 };
     63 
     64 struct line
     65 {
     66     point a,b;
     67     line(){}
     68     void input()
     69     {
     70     a.input();
     71     b.input();
     72     }
     73 
     74 
     75     
     76     int relation(point p)
     77     {
     78     int c = dblcmp(p.sub(a).det(b.sub(a)));
     79     if (c<0) return 1;
     80     if (c>0) return 2;
     81     return 3;
     82     }
     83     bool parallel(line v)
     84     {
     85     return dblcmp(b.sub(a).det(v.b.sub(v.a)))==0;
     86     }
     87     //0平行
     88     //1重合
     89     //2相交
     90     int linecrossline(line v)
     91     {
     92     if ((*this).parallel(v))
     93     {
     94         return v.relation(a)==3;
     95     }
     96     return 2;
     97     }
     98 
     99     point crosspoint(line v)
    100     {
    101     double a1 = v.b.sub(v.a).det(a.sub(v.a));
    102     double a2 = v.b.sub(v.a).det(b.sub(v.a));
    103     return point((a.x*a2-b.x*a1)/(a2-a1),(a.y*a2-b.y*a1)/(a2-a1));
    104     }
    105 }li[15][3];
    106 int main()
    107 {
    108   #ifndef  ONLINE_JUDGE 
    109    freopen("in.txt","r",stdin);
    110   #endif
    111     scanf("%d",&n);
    112     for ( int i = 1 ; i <= n ; i++)
    113     {
    114     li[i][1].input();
    115     li[i][2].input();
    116     }
    117 
    118     puts("INTERSECTING LINES OUTPUT");
    119     for ( int i = 1 ; i <=  n ; i++)
    120     {
    121     int tmp = li[i][1].linecrossline(li[i][2]);
    122 //    cout<<"tmp:"<<tmp<<endl;
    123     if (tmp==0)
    124     {
    125         puts("NONE");
    126     }
    127     if (tmp==1)
    128     {
    129         puts("LINE");
    130     }
    131     if (tmp==2)
    132     {
    133         printf("POINT ");
    134         li[i][1].crosspoint(li[i][2]).output();
    135     }
    136     }
    137     puts("END OF OUTPUT");
    138 
    139 
    140 
    141   
    142    
    143  #ifndef ONLINE_JUDGE  
    144   fclose(stdin);
    145   #endif
    146     return 0;
    147 }
    View Code
  • 相关阅读:
    《运营笔记》:主要是猫扑论坛运营经验。3星。
    《澄明之境》:二十年期货交易员的经验:投资没有圣杯,控制风险,在市场阶梯式上升过程中赚钱。3星
    《好好说话》:常见沟通场景的应对误区与应答思路、应答句式。4星。
    《尖叫感》:是近20-30年来尤其是近3-5年来的优秀广告文案的整理汇编。3星
    《石油,用得完吗》:石油会比较缓慢地被替代。3星
    Discuz常见大问题-如何自定义单个页面
    Discuz常见大问题-如何DIY一个独立页面
    Discuz常见大问题-如何使用云采集插件
    Discuz常见大问题-如何使用图片轮播器
    Discuz常见大问题-如何在自定义页面使用首页四格
  • 原文地址:https://www.cnblogs.com/111qqz/p/4942200.html
Copyright © 2011-2022 走看看