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. android adb端口被占用解决方法

    1.输入adb devices命令 C:\Users\Nick>adb devices List of devices attached adb server version (31) does ...

  2. Java中对象JSON格式化处理时的一个坑

    在项目中遇到了一个JSON的坑.记录下. 直接上代码: import java.util.ArrayList; import com.alibaba.fastjson.JSON; public cla ...

  3. httpclient的几种请求URL的方式

    一.httpclient项目有两种使用方式.一种是commons项目,这一个就只更新到3.1版本了.现在挪到了HttpComponents子项目下了,这里重点讲解HttpComponents下面的ht ...

  4. 基于DB的编程

    现在我们大多数的开发都是基于数据库,虽然数据库为我们提供了事务机制,保证存储的数据的ACID,但是,当我们在完成一个业务操作时,涉及到对数据库的大量操作,如果把这些操作在一个事务中,肯定是安全的,但是 ...

  5. urllib2模块的基本使用(四)

    urllib2库的基本使用 所谓网页抓取,就是把URL地址中指定的网络资源从网络流中读取出来,保存到本地. 在Python中有很多库可以用来抓取网页,我们先学习urllib2. urllib2 是 P ...

  6. uva-110-没有for循环的排序

    题意:看输出就懂了,暴力枚举题,字符串最大长度是8,所有长度等于8的长度是8!=1x2x3x4x5x6x7x8=40320,数据量比较小的.只是枚举的方向比较怪异,如下,长度等于3的串 a ab,ba ...

  7. OpenMP n 体问题

    ▶ <并行程序设计导论>第六章中讨论了 n 体问题,分别使用了 MPI,Pthreads,OpenMP 来进行实现,这里是 OpenMP 的代码,分为基本算法和简化算法(引力计算量为基本算 ...

  8. liquibase使用

    1. 创建表 drop database if exists mybatis; create database mybatis; use mybatis; create table mybatis.C ...

  9. Mysql 索引优化 - 1

    单表  范围查询 后面的索引会失效 双表  左右连接建立索引互相使用 三表   用小结果集驱动大表结果, 先优化括号里面的SQL, 保证JOIN被驱动的表上ON字段有索引 索引失效(常见原因) 全职匹 ...

  10. Tomcat 实战-调优方案

    来自:  http://blog.csdn.net/u010028869/article/details/51793821 来自:  https://www.cnblogs.com/baihuites ...