2018学校暑期集训第三天——几何基础

练习题B ——  POJ - 1269

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 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

#include<iostream>
#include<cstdio>
using namespace std;int main(void)
{double x1, x2, x3, x4;double y1, y2, y3, y4;double k1, k2, b1, b2;int n;cin >> n;cout << "INTERSECTING LINES OUTPUT" << endl;while(n--){scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);scanf("%lf%lf%lf%lf", &x3, &y3, &x4, &y4);if(x1==x2 && x3==x4){if(x1==x3)cout << "LINE" << endl;elsecout << "NONE" << endl;//continue;}else if(x1==x2 && x3!=x4){k2 = (y4-y3)/(x4-x3);b2 = y3 - k2*x3;printf("POINT %.2lf %.2lf\n", x1, k2*x1+b2);//continue;}else if(x3==x4 && x1!=x2){k1 = (y2-y1)/(x2-x1);b1 = y1 - k1*x1;printf("POINT %.2lf %.2lf\n", x3, k1*x3+b1);//continue;}else{k1 = (y2-y1)/(x2-x1);b1 = y1 - k1*x1;k2 = (y4-y3)/(x4-x3);b2 = y3 - k2*x3;if(k1==k2){if(b1==b2)cout << "LINE" << endl;elsecout << "NONE" << endl;}else{double x = (b2-b1)/(k1-k2);printf("POINT %.2lf %.2lf\n", x, k1*x+b1);}}   }cout << "END OF OUTPUT";return 0;
}

暑期集训3:几何基础 练习题C: POJ - 1269相关推荐

  1. 暑期集训3:几何基础 练习题H: POJ - 2456

    2018学校暑期集训第三天--几何基础 练习题H  --   POJ - 2456 Aggressive cows Farmer John has built a new long barn, wit ...

  2. 暑期集训3:几何基础 练习题G: HDU - 1052

    2018学校暑期集训第三天--几何基础 练习题G  --   HDU - 1052   (昨天加练题) Tian Ji -- The Horse Racing Here is a famous sto ...

  3. 暑期集训3:几何基础 练习题F:  CodeForces - 1007A ​​​​​​​

    2018学校暑期集训第三天--几何基础 练习题F  --   CodeForces - 1007A Reorder the Array You are given an array of intege ...

  4. 暑期集训3:几何基础 练习题D:  HDU - 2036 ​​​​​​​

    2018学校暑期集训第三天--几何基础 练习题D  --    HDU - 2036 改革春风吹满地 " 改革春风吹满地,  不会AC没关系;  实在不行回老家,  还有一亩三分地.  谢谢 ...

  5. 暑期集训3:几何基础 练习题B: HDU - 2001

    2018学校暑期集训第三天--几何基础 练习题B --  HDU - 2001 计算两点间的距离 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离. Input 输入数据有多组,每组 ...

  6. 暑期集训3:几何基础 练习题A: HDU - 2002

    2018学校暑期集训第三天--几何基础 练习题A  --   HDU - 2002 计算球体积 根据输入的半径值,计算球的体积. Input 输入数据有多组,每组占一行,每行包括一个实数,表示球的半径 ...

  7. 暑期集训2:ACM基础算法 练习题G:POJ - 1298

    2018学校暑期集训第二天--ACM基础算法 练习题G  --  POJ - 1298 The Hardest Problem Ever Julius Caesar lived in a time o ...

  8. 暑期集训1:C++STL 练习题E:POJ-2431

    2018学校暑期集训第一天--C++与STL 练习题E --  POJ - 2431 E - 二律背反的对偶 A group of cows grabbed a truck and ventured ...

  9. 暑期集训5:并查集 线段树 练习题G: HDU - 1754

    2018学校暑期集训第五天--并查集 线段树 练习题G  --   HDU - 1754 I Hate It 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.  这让 ...

最新文章

  1. android 常用 style,Android中 Styles和Themes
  2. Android Wifi 启动过程,AndroidP wifi启动流程
  3. 前后端开发的心得体会_社招后端三面总结以及学习经验感言(操详细)
  4. Mssql高级注入笔记.txt (转自:慕容小雨BLOG)
  5. 台式计算机日历表,Windows台式电脑怎么设置添加桌面日历透明便签?
  6. hibernate CascadeType属性说明
  7. 获取目录-Winform
  8. 人脸检测用什么模型_人脸检测模型:使用哪个以及为什么使用?
  9. [C++] [FLTK] 很久以前写的FLTK计算器
  10. MegaRAID Storage Manager RAID管理工具基本操作
  11. Linux下文件夹下子文件全部复制到多个文件夹中
  12. 电脑c盘格式化,如何恢复C盘文件?
  13. python图书销售系统
  14. MECHREVO X8ti 安装Ubuntu18.04,NVIDIA GTX 1060驱动、CUDA10
  15. HDOJ 1847Good Luck in CET-4 Everybody!(巴士博弈)
  16. linux的sssd服务,系统安全服务守护进程SSSD
  17. 【教程】EasyDSS演示模式播放ws-flv格式视频流,如何控制3分钟自动跳转登录页?
  18. spring cloud、gradle、父子项目、微服务框架搭建---搭建父子级多模块项目,并注册到Eureka注册中心(二)
  19. 风控体系及政策设计介绍
  20. Node.js安装,npm安装yarn步骤

热门文章

  1. JAVA-Socket通信笔记
  2. 定时清理tomcat日志文件
  3. tomcat server.xml中文版
  4. nagios报警的问题
  5. 人的一生有三件事不能等
  6. 打开云服务器连不上网,云服务器怎么连接网络连接不上
  7. php监听订单状态,ecshop数据库订单状态判断
  8. 村上春树 开始写作_如何克服对写作的恐惧并找到开始的动力
  9. 顺F速运国际版,你的密码漏点了
  10. dhcp动态主机配置协议