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. Ubuntu14.04下Sublime Text 3解决无法输入中文

    在Ubuntu 14.04中安装了SublimeText 3之后发现既然不支持输入中文,于是在网上搜罗一下,发现很多人遇到了同样的问题,但是解决办法大该就只有一个.下面根据自身的安装及解决办法总结如下 ...

  2. 源文件封装为IP的步骤

    因为模块的交接,最好将写好的源文件和生成的IP封装一个IP,然后再转交给其他的同事使用,这是一种好的习惯.但是对于,封装的过程还是需要注意一下.实际的看看步骤吧.1)将源文件和使用到的IP生成工程. ...

  3. 给iOS开发新手送点福利,简述UISegment的属性和用法

    UISegment属性 1.segmentedControlStyle 设置segment的显示样式. typedef NS_ENUM(NSInteger, UISegmentedControlSty ...

  4. 39. Combination Sum + 40. Combination Sum II + 216. Combination Sum III + 377. Combination Sum IV

    ▶ 给定一个数组 和一个目标值.从该数组中选出若干项(项数不定),使他们的和等于目标值. ▶ 36. 数组元素无重复 ● 代码,初版,19 ms .从底向上的动态规划,但是转移方程比较智障(将待求数分 ...

  5. Rhythmk 学习 Hibernate 02 - Hibernate 之 瞬时状态 离线状态 持久化状态 三状态

    by:rhythmk.cnblogs.com 1.Hibernate 三种状态: 1.1.三种定义(个人理解,不一定准确):  瞬时状态(transient):    不被session接管,且不存在 ...

  6. Linux下的终端快捷键

    今天才发现Linux下的终端有这么多好用的快捷键. Shift+Ctrl+T:新建标签页 Shift+Ctrl+W:关闭标签页 Ctrl+PageUp:前一标签页 Ctrl+PageDown:后一标签 ...

  7. tomcat8 安全加固

    本文基于tomcat8.0.24 1.删除文档和示例程序 [操作目的]删除示例文档 [加固方法]删除webapps/docs.examples.manager.ROOT.host-manager [是 ...

  8. C++全总结

    // CPPTEST.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include & ...

  9. jboss & eclipse 集成

    * 前提:       * 安装了 eclipse-jee-3.5.1       * 解压了 jboss5.1       * * "jboss tools" - "J ...

  10. 迷你MVVM框架 avalonjs 0.93发布

    这段时间吸取@limodou, @东灵等人的意见,做了以下改进 重构isArrayLike,提高avalon.each的性能,原来avalon.each是依赖于isArrayLike来判定是循环普通对 ...