POJ 1269 Intersecting Lines(判断两直线位置关系)
题目传送门:POJ 1269 Intersecting Lines
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
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
题目大意:
给你两条线段求这两条线段的位置关系(平行,重合,相交),若相交还要求出交点坐标
解题思路:
判断两直线位置关系
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define eps 1e-6
#define sgn(x) (fabs(x) < eps ? 0 : ((x) < 0 ? -1 : 1))
using namespace std;
struct point
{
double x, y;
point(double a = , double b = ) { x = a, y = b; }
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; }
};
struct line
{
point s,e;
line(){}
line(point a,point b) { s = a;e = b; }
///判断两直线位置关系,res返回相交点坐标
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()
{
int T;
point ans;
line l1,l2;
scanf("%d",&T);
printf("INTERSECTING LINES OUTPUT\n");
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&l1.s.x,&l1.s.y,
&l1.e.x,&l1.e.y,&l2.s.x,&l2.s.y,&l2.e.x,&l2.e.y);
pair<point,int> ans =l1&l2;
if( ans.second == ) printf("POINT %.2f %.2f\n",ans.first.x,ans.first.y);
else if(ans.second == ) printf("NONE\n");
else printf("LINE\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: 12421 Accepted: 55 ...
- POJ 1269 Intersecting Lines 判断两直线关系
用的是初中学的方法 #include <iostream> #include <cstdio> #include <cstring> #include <al ...
- 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
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- POJ 2398 - Toy Storage 点与直线位置关系
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5439 Accepted: 3234 Descr ...
- 简单几何(直线位置) POJ 1269 Intersecting Lines
题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...
- POJ 1269 Intersecting Lines【判断直线相交】
题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8342 Accepted: 378 ...
随机推荐
- SuperSocket证书节点新增配置属性 "storeLocation"
你可以指定你想要加载的证书的存储地点: <certificate storeName="My" storeLocation="LocalMachine" ...
- python yield 和 return 对比分析
相同点:都是返回函数执行的结果 不同点:return 在返回结果后结束函数的运行,而yield 则是让函数变成一个生成器,生成器每次产生一个值(yield语句),函数被冻结,被唤醒后再产生一个值 例子 ...
- SpringMVC参数校验,包括JavaBean和基本类型的校验
该示例项目使用SpringBoot,添加web和aop依赖. SpringMVC最常用的校验是对一个javaBean的校验,默认使用hibernate-validator校验框架.而网上对校验单个参数 ...
- 手把手教你用Python实现自动特征工程
任何参与过机器学习比赛的人,都能深深体会特征工程在构建机器学习模型中的重要性,它决定了你在比赛排行榜中的位置. 特征工程具有强大的潜力,但是手动操作是个缓慢且艰巨的过程.Prateek Joshi,是 ...
- codeforces 616D
题意:给你n个数,找出一个最大的区间,满足:不同的数值个数不超过k; //我开始又看错题了. 以为是找出一个最大区间,里面的数的最大值不超过k; 思路:利用一个窗口滑动,左端点表示当前位置,右端点表示 ...
- python进阶之面向对象初识
面向对象 不同于面向过程的编程思想,面向对象是一种将程序抽象为一个个对象的编程思想,能更好的处理现实世界到的一些复杂问题. 通过下面的例子来初步了解面向对象的编程方式. class Person: # ...
- P1034 台阶问题一
题目描述 有 \(N\) 级的台阶,你一开始在底部,每次可以向上迈最多2级台阶(最少1级),问到达第 \(N\) 级台阶有多少种不同方式. 输入格式 一个正整数 \(N(\le 20)\) . 输出格 ...
- MySQL查询语句积累
#查询名字中带李且名字是两个字的所有学生信息 SELECT * FROM user_test WHERE user_name LIKE '李_';
- Python安装jpype调用java,安装jaydebeapi通过jdbc连接数据库
pip install JPype1或下载JPype1-0.7.0.tar.gz包 经常出现需要安装VC++服务等 测试代码如下: # Author: zfh import jpype,os,time ...
- springboot中redis做缓存时的配置
import com.google.common.collect.ImmutableMap;import org.slf4j.Logger;import org.slf4j.LoggerFactory ...