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

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

Source

——————————————————————————————————————题目的意思是给出4个坐标确定两条直线,问这两条直线的关系平行or重合or相交(求焦点)

先根据斜率判关系(斜率不存在特判)再套几何模板即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset> using namespace std; #define LL long long
const int INF=0x3f3f3f3f; struct Point
{
double x,y;
};
typedef struct Point point; point f(point u1,point u2,point v1,point v2)
{
point ret=u1;
double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
ret.x+=(u2.x-u1.x)*t;
ret.y+=(u2.y-u1.y)*t;
return ret;
} int main()
{
int T;
while(~scanf("%d",&T))
{
printf("INTERSECTING LINES OUTPUT\n");
while(T--)
{
point u1,u2,v1,v2;
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&u1.x,&u1.y,&u2.x,&u2.y,&v1.x,&v1.y,&v2.x,&v2.y);
if(u1.x==u2.x||v1.x==v2.x)
{
if(u1.x==u2.x&&v1.x==v2.x)
{
if(u1.x==v1.x) printf("LINE\n");
else printf("NONE\n");
}
else if(u1.x==u2.x)
{
double k2=(v1.y-v2.y)/(v1.x-v2.x);
printf("POINT %.2f %.2f\n",u1.x,v2.y-k2*v2.x+k2*u1.x);
}
else
{
double k1=(u1.y-u2.y)/(u1.x-u2.x);
printf("POINT %.2f %.2f\n",v1.x,u2.y-k1*u2.x+k1*v1.x);
}
}
else
{
double k1=(u1.y-u2.y)/(u1.x-u2.x);
double k2=(v1.y-v2.y)/(v1.x-v2.x);
if(k1!=k2)
{
point ans=f(u1,u2,v1,v2);
printf("POINT %.2f %.2f\n",ans.x,ans.y);
}
else
{
double ans1=k1*v1.x+u1.y-k1*u1.x;
if(ans1==v1.y)
printf("LINE\n");
else
printf("NONE\n");
}
}
}
printf("END OF OUTPUT\n");
}
return 0;
}

POJ1269 Intersecting Lines 2017-04-16 19:43 50人阅读 评论(0) 收藏的更多相关文章

  1. HDU1879 继续畅通工程 2017-04-12 19:12 50人阅读 评论(0) 收藏

    继续畅通工程 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

  2. HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏

    Easy Summation                                                             Time Limit: 2000/1000 MS ...

  3. 总结分享十大iOS开发者最喜爱的库 分类: ios相关 app相关 2015-04-03 16:43 320人阅读 评论(0) 收藏

    该10大iOS开发者最喜爱的库由"iOS辅导团队"成员Marcelo Fabri组织投票选举而得,参与者包括开发者团队,iOS辅导团队以及行业嘉宾.每个团队都要根据以下规则选出五个 ...

  4. Hadoop入门经典:WordCount 分类: A1_HADOOP 2014-08-20 14:43 2514人阅读 评论(0) 收藏

    以下程序在hadoop1.2.1上测试成功. 本例先将源代码呈现,然后详细说明执行步骤,最后对源代码及执行过程进行分析. 一.源代码 package org.jediael.hadoopdemo.wo ...

  5. 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...

  6. The Pilots Brothers' refrigerator 分类: POJ 2015-06-15 19:34 12人阅读 评论(0) 收藏

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20304 ...

  7. IP Address 分类: POJ 2015-06-12 19:34 12人阅读 评论(0) 收藏

    IP Address Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 19125   Accepted: 11053 Desc ...

  8. HDU6026 Deleting Edges 2017-05-07 19:30 38人阅读 评论(0) 收藏

    Deleting Edges                                                                                  Time ...

  9. HDU6029 Happy Necklace 2017-05-07 19:11 45人阅读 评论(0) 收藏

    Happy Necklace                                                                           Time Limit: ...

随机推荐

  1. 在Chrome调试器中引入jQuery

    在Console中输入以下代码并回车,Console显示"function (a,b){return new m.fn.init(a,b)}"说明导入成功,就可以在Console中 ...

  2. Android 查看Android版本的方法

    1.通过源码查看 Android 版本 路径:build/core/version_defaults.mk PLATFORM_VERSION := 2.通过编译时终端输出查看 ============ ...

  3. emacs配置emacs-clang-complete-async

    debian下需要安装apt安装下clang和llvm sudo apt-get install llvm-dev sudo apt-get install libclang-dev 网上抄来一个大神 ...

  4. post参数的方法 json data 和特别的传参

    json格式传参: 那么久使用json的方式传参: json=payload data格式传参: 其他方式传参: 在webFormes里 value 的值不是普通的字符 要把value值先序列化在放入 ...

  5. window.onload()和$(document).ready()区别

    执行时间:window.onload:必须等待网页中所有的内容加载完毕后(包括图片)才能执行;$(document).ready();网页中所有DOM结构绘制完毕后就执行,可能DOM元素关联的东西并没 ...

  6. 《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #11cpuset

    HACK #11cpuset 本节介绍控制物理CPU分配的cpuset.cpuset是Linux控制组(Cgroup)之一,其功能是指定特定进程或线程所使用的CPU组.另外,除CPU以外,同样还能指定 ...

  7. Quartz实现JAVA定时任务的动态配置

    什么是动态配置定时任务? 首先说下这次主题,动态配置.没接触过定时任务的同学可以先看下此篇:JAVA定时任务实现的几种方式 定时任务实现方式千人千种,不过基础的无外乎 1.JDK 的Timer类 2. ...

  8. 自定义Hibernate Validator约束

    定义注解 实现一个只能输入指定状态的约束条件 import javax.validation.Constraint; import javax.validation.Payload; import j ...

  9. 配置myslq提示 the configuration step starting server is taking longer than expected we apologize for thi

    .卸载重新安装,勾选日志配置选项,自定义日志输出路径

  10. Elastic Search的学习

    那些必须要知道的事儿 自然语言处理 自然语言处理之中文分词器 什么是Apache Lucene 什么是elasticsearch 搭建elasticsearch环境 Windows下 Java环境配置 ...