Leyni, LOLI and Line

Time Limit: 1000 MS    Memory Limit: 65536 K

Total Submit: 181(54 users)   Total Accepted: 88(52 users)       Rating:         Special Judge: No

Description

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.

Input

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

Output

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.

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

POINT 2.00 2.00

NONE

LINE

POINT 2.00 5.00

POINT 1.07 2.20

Hint

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.

Author

哈理工2011春季校赛


  解析几何,斜截式的应用

  利用斜截式判断两条直线位置关系(共线LINE、不相交NONE、相交POINT),相交的话需要输出交点坐标。

  思路是先分别求出两条直线斜截式的斜率k和截距b,之后就是通过比较确定两条直线的位置关系:

  if 两条直线斜率相等

    if 两条直线截距也相等

      共线 LINE

    else 截距不相等

      平行,无交点 NONE

  else if 两条直线都垂直

    if 两条直线横坐标相等

      共线 LINE

    else 横坐标不相等

      平行,无交点 NONE

  else if 第一条直线垂直

    相交 POINT(交点用解析几何方法就能求出)

  else if 第二条直线垂直

    相交 POINT(同上)

  else 排除了斜率相等和垂直的情况,剩下的一定相交

    相交 POINT(联立两直线方程)

  用斜截式解决几何问题需要注意垂直的时候是没有斜率k的,所以需要将垂直的情况拿出来单独考虑。

  代码

 #include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
while(n--){
double x1,y1,x2,y2,x3,y3,x4,y4;
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
double k1=(y2-y1)/(x2-x1),k2=(y4-y3)/(x4-x3);
double b1=y1-k1*x1,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);
}
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hrbustoj 1104:Leyni, LOLI and Line(解析几何,斜截式的应用)的更多相关文章

  1. hrbustoj 1161:Leyni(树状数组练习)

    LeyniTime Limit: 3000 MS Memory Limit: 65536 KTotal Submit: 260(59 users) Total Accepted: 80(55 user ...

  2. 【BZOJ 1007】【HNOI 2008】水平可见直线 解析几何

    之前机房没网就做的这道题,用的解析几何判断交点横坐标 #include<cmath> #include<cstdio> #include<cstring> #inc ...

  3. UVa 11524:In-Circle(解析几何)

    Problem EIn-CircleInput: Standard Input Output: Standard Output In-circle of a triangle is the circl ...

  4. fragment显示 Binary XML file line #12: Error inflating class fragment 错误

    问题 最近换了新机子,今天在静态用fragment时突然发现闪退,一看显示 Binary XML file line #12: Error inflating class fragment 错误 后面 ...

  5. BZOJ 1502: [NOI2005]月下柠檬树 [辛普森积分 解析几何 圆]

    1502: [NOI2005]月下柠檬树 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1070  Solved: 596[Submit][Status] ...

  6. 对称点line

    2 线 题⽬描述 有一天rax看到了男神,有时可爱美丽的她派ypq去把yyqx抓回来给rax欣赏,但ypq和yyqx间隔了一条线,她必须跳到yyqx以前待得点的对称点才有可能抓到yyqx给出⼀条直线, ...

  7. 【BZOJ】1610: [Usaco2008 Feb]Line连线游戏(几何)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1610 两种做法,一种计算几何,一种解析几何,但是计算几何的复杂度远远搞出解析集合(虽然精度最高) 计 ...

  8. PAT 甲级 1104 sum of Number Segments

    1104. Sum of Number Segments (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Pen ...

  9. PAT甲级——1104 Sum of Number Segments (数学规律、自动转型)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90486252 1104 Sum of Number Segmen ...

随机推荐

  1. IntelliJ Idea各种技巧设置笔记和错误解决

    版本控制 GitHub GitHub提示找不到路径: 解决方法:去官方下载gitHub,然后在以下路径找到Git.exe并设置 C:\Users\你的用户\AppData\Local\GitHub\P ...

  2. python --正则学习

    re的正则表达式语法    正则表达式语法表如下: re.match re.match 尝试从字符串的开始匹配一个模式,匹配成功返回match object,否则返回None. 如:下面的例子匹配第一 ...

  3. C++中四种类型转换以及const_cast是否能改变常量的问题

    we have four specific casting operators:dynamic_cast, reinterpret_cast, static_cast and const_cast. ...

  4. Android的xml/assets/raw资源使用具体解释

    一.assets/xml/raw资源介绍 1.assets资源文件夹:assets文件夹下存放的资源代表应用无法直接訪问的原生资源,这些文件将原封不动的存储到设备上,不会被编译为二进制形式,訪问方式是 ...

  5. AutoFac文档8(转载)

    目录 开始 Registering components 控制范围和生命周期 用模块结构化Autofac xml配置 与.net集成 深入理解Autofac 指导 关于 词汇表 泛型 给定一个开放的泛 ...

  6. ubuntu更新出错--Could not get lock /var/lib/dpkg/lock

    ubuntu在vps上安装好后,通常第一个命令是更新系统软件.然而在运行的过程中,却出现这样的错误: E: Could not get lock /var/lib/dpkg/lock - open ( ...

  7. MySQL5.0存储过程教程

    Introduction 简介 MySQL 5.0 新特性教程是为需要了解5.0版本新特性的MySQL老用户而写的.简单的来说是介绍了“存储过程.触发器.视图.信息架构视图”,在此感谢译者陈朋奕的努力 ...

  8. Atitit.mssql 数据库表记录数and 表体积大小统计

    Atitit.mssql 数据库表记录数and 表体积大小统计 1. EXEC   sp_MSforeachtable   "EXECUTE   sp_spaceused   '?'&quo ...

  9. VBA学习笔记(1)----VBA对象属性方法

    'VBA对象 'VBA中的对象其实就是我们操作的具有方法.属性的excel中支持的对象 'Excel中的几个常用对象表示方法 '1.工作簿 ' Workbooks 代表工作簿集合,所有的工作簿,Wor ...

  10. boa 服务的启动

    使用 buildroot 添加 boa 服务后,通过命令 boa 不能启动该服务,就研究了一下boa.conf的配置. etc/boa/boa.conf # 更改user 和Group 为root. ...