Intersecting Lines
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 15145   Accepted: 6640

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

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

Sample Output

  1. INTERSECTING LINES OUTPUT
  2. POINT 2.00 2.00
  3. NONE
  4. LINE
  5. POINT 2.00 5.00
  6. POINT 1.07 2.20
  7. END OF OUTPUT

Source


呵呵 这种裸题...
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <vector>
  7. using namespace std;
  8. typedef long long ll;
  9. const double eps=1e-;
  10. inline int read(){
  11. char c=getchar();int x=,f=;
  12. while(c<''||c>''){if(c=='-')f=-; c=getchar();}
  13. while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
  14. return x*f;
  15. }
  16. inline int sgn(double x){
  17. if(abs(x)<eps) return ;
  18. else return x<?-:;
  19. }
  20. struct Vector{
  21. double x,y;
  22. Vector(double a=,double b=):x(a),y(b){}
  23. bool operator <(const Vector &a)const{
  24. return x<a.x||(x==a.x&&y<a.y);
  25. }
  26. void print(){
  27. printf("%lf %lf\n",x,y);
  28. }
  29. };
  30. typedef Vector Point;
  31. Vector operator +(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
  32. Vector operator -(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
  33. Vector operator *(Vector a,double b){return Vector(a.x*b,a.y*b);}
  34. Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);}
  35. bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==&&sgn(a.y-b.y)==;}
  36.  
  37. double Cross(Vector a,Vector b){
  38. return a.x*b.y-a.y*b.x;
  39. }
  40. double Dot(Vector a,Vector b){
  41. return a.x*b.x+a.y*b.y;
  42. }
  43. double DisPP(Point a,Point b){
  44. Point t=a-b;
  45. return sqrt(t.x*t.x+t.y*t.y);
  46. }
  47. struct Line{
  48. Point s,t;
  49. Line(){}
  50. Line(Point p,Point v):s(p),t(v){}
  51. };
  52. bool isLSI(Line l1,Line l2){
  53. Vector v=l1.t-l1.s,u=l2.s-l1.s,w=l2.t-l1.s;
  54. return sgn(Cross(v,u))!=sgn(Cross(v,w));
  55. }
  56. bool isSSI(Line l1,Line l2){
  57. return isLSI(l1,l2)&&isLSI(l2,l1);
  58. }
  59. Point LI(Line a,Line b){
  60. Vector v=a.s-b.s,v1=a.t-a.s,v2=b.t-b.s;
  61. double t=Cross(v2,v)/Cross(v1,v2);
  62. return a.s+v1*t;
  63. }
  64. double x,y,x2,y2;
  65. Line l1,l2;
  66. void solve(){
  67. if(sgn(Cross(l1.t-l1.s,l2.t-l2.s))==){
  68. Vector v=l1.t-l1.s,u=l2.s-l1.s,w=l2.t-l1.s;
  69. if(sgn(Cross(v,u))==&&sgn(Cross(v,w))==) puts("LINE");
  70. else puts("NONE");
  71. }else{
  72. Point p=LI(l1,l2);
  73. printf("POINT %.2f %.2f\n",p.x,p.y);
  74. }
  75. }
  76. int main(int argc, const char * argv[]) {
  77. int T=read();
  78. puts("INTERSECTING LINES OUTPUT");
  79. while(T--){
  80. scanf("%lf%lf%lf%lf",&x,&y,&x2,&y2);
  81. l1=Line(Point(x,y),Point(x2,y2));
  82. scanf("%lf%lf%lf%lf",&x,&y,&x2,&y2);
  83. l2=Line(Point(x,y),Point(x2,y2));
  84. solve();
  85. }
  86. puts("END OF OUTPUT");
  87. return ;
  88. }
 

POJ1269 Intersecting Lines[线段相交 交点]的更多相关文章

  1. [poj1269]Intersecting Lines

    题目大意:求两条直线的交点坐标. 解题关键:叉积的运用. 证明: 直线的一般方程为$F(x) = ax + by + c = 0$.既然我们已经知道直线的两个点,假设为$(x_0,y_0), (x_1 ...

  2. POJ1269:Intersecting Lines(判断两条直线的关系)

    题目:POJ1269 题意:给你两条直线的坐标,判断两条直线是否共线.平行.相交,若相交,求出交点. 思路:直线相交判断.如果相交求交点. 首先先判断是否共线,之后判断是否平行,如果都不是就直接求交点 ...

  3. poj 1269 Intersecting Lines(直线相交)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8637   Accepted: 391 ...

  4. poj1269 intersecting lines【计算几何】

    We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a p ...

  5. POJ1269 Intersecting Lines 2017-04-16 19:43 50人阅读 评论(0) 收藏

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15478   Accepted: 67 ...

  6. Pipe - POJ 1039(线段相交交点)

    题目大意:有一个不反光并且不透光的管道,现在有一束光线从最左端进入,问能达到的最右端是多少,输出x坐标.   分析:刚开始做是直接枚举两个点然后和管道进行相交查询,不过这样做需要考虑的太多,细节不容易 ...

  7. POJ 1269 Intersecting Lines(线段相交,水题)

    id=1269" rel="nofollow">Intersecting Lines 大意:给你两条直线的坐标,推断两条直线是否共线.平行.相交.若相交.求出交点. ...

  8. POJ 1269 Intersecting Lines(直线相交判断,求交点)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8342   Accepted: 378 ...

  9. poj 1269 Intersecting Lines——叉积求直线交点坐标

    题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...

随机推荐

  1. SQL强化(三) 自定义函数

    ---恢复内容开始--- Oracle中我们可以通过自定义函数去做一些逻辑判断,这样可以减少查询语句,提高开发效率 create  -- 创建自定义函数 or replace -- 有同名函数就替换, ...

  2. 微信小程序实现淡入淡出效果(页面跳转)

    //目前小程序没有fadeIn(),fadeOut()方法所以还是本方法手写  <!--wxml--><!--蒙版(渐出淡去效果)--><view class=" ...

  3. vmstat & mpstat & w

    vmstat # vmstat 3 2procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- ...

  4. 什么是redis,redis能做什么,redis应用场景

    Redis是一个key-value存储系统.Redis的出现,很大程度补偿了memcached这类key/value存储的不足,在部分场合可以对关系数据库起到很好的补充作用.这篇文章小编为大家分享了在 ...

  5. dede 提交表单 发送邮件

    第一步:要到dede后台设置好邮箱的资料,并且确定所用的邮箱开启了smtp 第二步:找到/plus/diy.php在 [cce]$query = "INSERT INTO `{$diy-&g ...

  6. shareInstance

    2.+(id)shareInstance; 外界初始化得到单例类对象的唯一借口,这个类方法返回的就是instance,即类的一个对象, 如果instance为空,则实例化一个对象,如果不为空,则直接返 ...

  7. oracle11g安装教程(注意事项及图文教程)

    Oracle安装与重装注意事项 1.安装oracle(**) 注意:安装Oracle之前确定自己的主机(计算机)名要保证计算机名是英文的. 1.oracle的安装文件不要放在含有中文的目录当中,如:d ...

  8. Vue.js学习网址

    Vue官网:http://cn.vuejs.org/v2/guide/index.html 淘宝镜像:http://npm.taobao.org/ Vue-router:https://router. ...

  9. Mac下Charles Contents乱码解决办法

    用到Charles,下载最新的4.0.1版本,但是发生乱码问题.百度好久才找到个靠谱的,那些说什么在Info.plist文件加字符串的,都是假的,反正我是试了都没用,这里记下详细的操作步骤解决: 1. ...

  10. (1-1)SpringCloud-Eureka:服务的注册与发现

    SpringCloud Eureka是SpringCloud Netflix服务套件中的一部分,它基于Netflix Eureka做了二次封装,主要负责完成微服务架构中的服务治理功能.下面来做一个示例 ...