POJ 1269 Intersecting Lines 判断两直线关系
用的是初中学的方法
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define eps 1e-8
using namespace std; struct Point
{
double x,y;
Point() {};
Point(double xx,double yy)
{
x=xx;
y=yy;
}
}ans; int getCross(Point p1,Point p2,Point q1,Point q2)
{
double k1=(p1.y-p2.y)/(p1.x-p2.x);
double k2=(q1.y-q2.y)/(q1.x-q2.x);
double b1=p1.y-k1*p1.x;
double b2=q1.y-k2*q1.x;
if(p1.x==p2.x && q1.x==q2.x) return p1.x==q1.x? 1:-1;
if(p1.x==p2.x)
{
ans=Point(p1.x,k2*p1.x+b2);
return 0;
}
if(q1.x==q2.x)
{
ans=Point(q1.x,k1*q1.x+b1);
return 0;
}
if(fabs(k1-k2)<eps) return fabs(b1-b2)<eps? 1:-1;
ans.x=(b2-b1)/(k1-k2);
ans.y=k1*ans.x+b1;
return 0;
} int main()
{
// freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
Point pot[4];
puts("INTERSECTING LINES OUTPUT");
while(t--)
{
double x,y;
for(int i=0; i<4; i++)
{
scanf("%lf%lf",&x,&y);
pot[i]=Point(x,y);
}
int tmp=getCross(pot[0],pot[1],pot[2],pot[3]);
if(tmp==-1) puts("NONE");
else if(tmp==1) puts("LINE");
else printf("POINT %.2f %.2f\n",ans.x,ans.y);
}
puts("END OF OUTPUT");
return 0;
}
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 (判断直线位置关系)
题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...
- 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
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- 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 ...
- poj 1269 Intersecting Lines
题目链接:http://poj.org/problem?id=1269 题目大意:给出四个点的坐标x1,y1,x2,y2,x3,y3,x4,y4,前两个形成一条直线,后两个坐标形成一条直线.然后问你是 ...
- POJ 1269 - Intersecting Lines - [平面几何模板题]
题目链接:http://poj.org/problem?id=1269 Time Limit: 1000MS Memory Limit: 10000K Description We all know ...
- poj 1269 Intersecting Lines——叉积求直线交点坐标
题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...
随机推荐
- Linux PATH环境变量及作用(初学者必读)
Linux PATH环境变量及作用(初学者必读) < 什么是环境变量,Linux环境变量有哪些?Linux打包(归档)和压缩 > <Linux就该这么学>是一本基于最新Linu ...
- 说明位图,矢量图,像素,分辨率,PPI,DPI?
说明位图,矢量图,像素,分辨率,PPI,DPI? 显示全部 关注者 28 被浏览 7,031 关注问题写回答 邀请回答 添加评论 分享 2 个回答 默认排序 刘凯 21 人赞同了 ...
- 9.11 strace:跟踪进程的系统调用 、ltrace:跟踪进程调用库函数
strace 是Linux环境下的一款程序调试工具,用于检查一个应用程序所使用的系统调用以及它所接收的系统信息.strace会追踪程序运行时的整个生命周期,输出每一个系统调用的名字.参数.返回值和执行 ...
- 面试侃集合 | SynchronousQueue非公平模式篇
面试官:好了,你也休息了十分钟了,咱们接着往下聊聊SynchronousQueue的非公平模式吧. Hydra:好的,有了前面公平模式的基础,非公平模式理解起来就非常简单了.公平模式下,Synchro ...
- 分层条件关系网络在视频问答VideoQA中的应用:CVPR2020论文解析
分层条件关系网络在视频问答VideoQA中的应用:CVPR2020论文解析 Hierarchical Conditional Relation Networks for Video Question ...
- TVM在ARM GPU上优化移动深度学习
TVM在ARM GPU上优化移动深度学习 随着深度学习的巨大成功,将深度神经网络部署到移动设备的需求正在迅速增长.与在台式机平台上所做的类似,在移动设备中使用GPU可以提高推理速度和能源效率.但是,大 ...
- 深度学习白平衡(Color Constancy,AWB):ICCV2019论文解析
深度学习白平衡(Color Constancy,AWB):ICCV2019论文解析 What Else Can Fool Deep Learning? Addressing Color Constan ...
- 深度学*点云语义分割:CVPR2019论文阅读
深度学*点云语义分割:CVPR2019论文阅读 Point Cloud Oversegmentation with Graph-Structured Deep Metric Learning 摘要 本 ...
- 常用深度学习框——Caffe/ TensorFlow / Keras/ PyTorch/MXNet
常用深度学习框--Caffe/ TensorFlow / Keras/ PyTorch/MXNet 一.概述 近几年来,深度学习的研究和应用的热潮持续高涨,各种开源深度学习框架层出不穷,包括Tenso ...
- Python-selenium,切换句柄及封装
一.获取当前句柄及所有句柄 handle=driver.current_window_handle #获取当前窗口句柄print(handle)handles=driver.window_handle ...