POJ 1269 Intersecting Lines(直线相交判断,求交点)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8342 | Accepted: 3789 |
Description
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
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
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
/************************************************************
* Author : kuangbin
* Email : kuangbin2009@126.com
* Last modified : 2013-07-14 08:54
* Filename : POJ1269IntersectingLines.cpp
* Description :
* *********************************************************/ #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <math.h> using namespace std;
const double eps = 1e-;
int sgn(double x)
{
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
}
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x = _x;y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x,y - b.y);
}
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
};
struct Line
{
Point s,e;
Line(){}
Line(Point _s,Point _e)
{
s = _s;e = _e;
}
pair<Point,int> operator &(const Line &b)const
{
Point res = s;
if(sgn((s-e)^(b.s-b.e)) == )
{
if(sgn((b.s-s)^(b.e-s)) == )
return make_pair(res,);//两直线重合
else return make_pair(res,);//两直线平行
}
double t = ((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
res.x += (e.x - s.x)*t;
res.y += (e.y - s.y)*t;
return make_pair(res,);//有交点
}
};
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
double x1,y1,x2,y2,x3,y3,x4,y4;
printf("INTERSECTING LINES OUTPUT\n");
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
Line line1 = Line(Point(x1,y1),Point(x2,y2));
Line line2 = Line(Point(x3,y3),Point(x4,y4));
pair<Point,int> ans = line1 & line2;
if( ans.second == )printf("POINT %.2lf %.2lf\n",ans.first.x,ans.first.y);
else if(ans.second == )printf("LINE\n");
else printf("NONE\n");
}
printf("END OF OUTPUT\n"); return ;
}
POJ 1269 Intersecting Lines(直线相交判断,求交点)的更多相关文章
- poj 1269 Intersecting Lines(直线相交)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8637 Accepted: 391 ...
- POJ 1269 - Intersecting Lines 直线与直线相交
题意: 判断直线间位置关系: 相交,平行,重合 include <iostream> #include <cstdio> using namespace std; str ...
- POJ 1269 Intersecting Lines 直线交
不知道谁转的计算几何题集里面有这个题...标题还写的是基本线段求交... 结果题都没看就直接敲了个线段交...各种姿势WA一遍以后发现题意根本不是线段交而是直线交...白改了那个模板... 乱发文的同 ...
- POJ 1269 Intersecting Lines(判断两直线位置关系)
题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...
- POJ 1269 Intersecting Lines【判断直线相交】
题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- POJ 1269 Intersecting Lines (判断直线位置关系)
题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...
- poj 1269 Intersecting Lines——叉积求直线交点坐标
题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...
- poj 1269 Intersecting Lines(判断两直线关系,并求交点坐标)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12421 Accepted: 55 ...
随机推荐
- Remember that ordinal parameters are 1-based!
问题发生的原因是:hql语句里不需要参数,却添加了一个参数,删掉添加参数的语句就可以了!
- .net4.0下 解决asp.net中“从客户端中检测到有潜在危险的Request.Form值”的错误
asp.net 2.0 通常解决办法 方案一: 将.aspx文件中的page项添加ValidateRequest="false" ,如下: <%@ Page Validate ...
- volley(5) 参数total_remain:totalqty, data:[{ bar_status:XX , bar_code: "XX",bar_remain:XX, bar_whcode:"XX" , bar_prodcode:"XX",bar_id:XX,bar_location: "XX", pr_detail: "XX" , bar_batchcode:method:POST
1. 来源 : WHCombineBatchFragment.java 2. 部分代码 WHCombineBatchFragmentCombineBtnClickEvent whc2;private ...
- mongodb数据备份与还原
1)简单数据的导出与导入导出:./mongoexport -d test -c users -o /tmp/users.out 导入:./mongoimport -d test -c users /t ...
- scala学习笔记(3):类
1 类 (1) scala把主构造函数放到类的定义中,让定义字段及相应方法变得简单起来. class People(age: Int, name: String) scala会自动将这个类变成publ ...
- *ecshop 模板中foreach用法详解
1.foreach分以下几个参数 from, item, name, iteration, index 2.使用foreach循环 如果php要传递一个数组(如:$array)给ecshop ...
- 使用git自动将子工程发布到百度开放云上
我的项目中包含多个子工程,如web工程.python工程等.我在项目的根目录下建立了git管理,因此如果使用git push只能把整个项目推送上去,但我只想推送web工程目录.因此,编写了cmd脚本如 ...
- Apache加载PHP.ini顺序
网上找到一份关于Apache加载PHP.ini顺序的文档: (1) apache的httpd.conf中的PhpIniDir: (2) 注册表键值:HKEY_LOCAL_MACHINE->SOF ...
- C# Datatable的Select方法
lubiaopan 原文 Datatable的Select()方法简介 DataTable是我们在进行开发时经常用到的一个类,并且经常需要对DataTable中的数据进行筛选等操作,下面就介绍一下Da ...
- C# 异步操作 async await 的用法
1. async与 await 成对出现 async 在方法前使用 ,方法体面面用 await . 2. 使用async 和await定义异步方法不会创建新线程. 3.await 后面一定是一个扫行 ...