Hust oj 1104 Leyni, LOLI and Line(线段相交)
来源:互联网 发布:淘宝账号能注销掉吗 编辑:程序博客网 时间:2024/06/05 09:44
Professor Leyni likes to help LOLIs with their math.
This time, Leyni meets several LOLIs in the classroom and gets several problems about "Intersecting Lines".
The LOLIs want to know how and where two lines intersect.Leyni asks you to help him to answer.
There are multiple test cases. The first line of input is an integer T indicating the number of test cases. Then T test cases follow.
For each test case:
Line 1. This line contains 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).
All numbers required by this problem will be in the range [-1000, 1000].
For each test case:
Line 1.If there is no intersection, output "NONE". If they are the same line, output "LINE". Otherwise output the x and y coordinates of the point, correct to two decimal places as the sample output.
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
POINT 2.00 2.00
NONE
LINE
POINT 2.00 5.00
POINT 1.07 2.20
注意与X轴垂直是没有斜率,需要特判
#include<cstdio>#include<cstring>#include<iostream>using namespace std;int t;double x1,x2,x3,x4,y1,y2,y3,y4;double k1,k2,b1,b2;int main(){ scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); k1 = (y2-y1) / (x2-x1); b1 = y1 - k1 * x1; k2 = (y4-y3) / (x4-x3); b2 = y3 - k2 * x3; if(k1 == k2) { if(b1 == b2) printf("LINE\n"); else printf("NONE\n"); } else if(x1 == x2 && x3 == x4) { if(x1 == x3) printf("LINE\n"); else printf("NONE\n"); } else if(x1 == x2) { printf("POINT %.2lf %.2lf\n",x1,k2*x1+b2); } else if(x3 == x4) { printf("POINT %.2lf %.2lf\n",x3,k1*x3+b1); } else { double x = (b2 - b1) / (k1 - k2); printf("POINT %.2lf %.2lf\n",x,k1*x+b1); } }}
- Hust oj 1104 Leyni, LOLI and Line(线段相交)
- Hust oj 1384 Leyni, LOLI and Toasts(水题)
- Hust oj 1559 线段相交(叉积)
- ACM-计算几何之Leyni, LOLI and Line——hrbust1104
- 哈理工OJ 1161 Leyni(线段树)
- leyni,loli,cap
- Hust oj 1189 区间最大值 II(线段树RMQ)
- Hust oj 2043 长长长长龙(线段树RMQ)
- Hrbust 1390 Leyni, LOLI and Numbers【思维+树状数组+二分+双向链表模拟】好题!好题!好题!
- 南邮 OJ 1041 线段相交
- 哈理工OJ 1559 线段相交(计算几何)
- Hust oj 2084(大数)
- 哈理工 oj 1161 Leyni
- [CG]Intersection of Line Segments(0163)(计算几何,求线段是否相交)
- Hust oj 2038 联系网络(MST)
- Hust oj 2234 土豪银行(贪心)
- Hust oj 1143 泉水(dfs)
- Hust oj 2113 Count(Map)
- git的简单认识
- 单精度float变量在内存中的存储形式
- js中的前进和后退是如何实现的
- 冒泡排序
- Python 模块RE整理
- Hust oj 1104 Leyni, LOLI and Line(线段相交)
- LeetCode之Find the Difference(Java版)
- [NSConcreteMutableData wbsdk_base64EncodedString]: unrecognized selector sent to instance
- canvas 实现环形进度条
- Java多线程之同步容器与并发容器
- inux进程间通信——消息队列
- 学习之路
- 【leetcode】312. Burst Balloons
- 坐标的旋转,翻转