http://poj.org/problem?id=1269

题目大意:给四个点,求前两个点所构成的直线和后两个点所构成的直线的位置关系(平行,重合,相交),如果是相交,输出交点坐标。

——————————————————————

http://blog.csdn.net/zxy_snow/article/details/6341282 这个人的博客有详细的证明过程,这里直接拿来用即可。

应当优先判断向量平行,这样再判断是否重合能更方便些。

#include<cstdio>
#include<queue>
#include<cctype>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef double dl;
inline int read(){
int X=,w=;char ch=;
while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
while(isdigit(ch))X=(X<<)+(X<<)+(ch^),ch=getchar();
return w?-X:X;
}
struct point{//既是向量又是点
dl x;
dl y;
}q[];
inline point getmag(point a,point b){
point s;
s.x=b.x-a.x;s.y=b.y-a.y;
return s;
}
inline int multiX(point a,point b){
return a.x*b.y-b.x*a.y;
}
inline bool parallel_mag(point a,point b){
if(a.x*b.y==a.y*b.x)return ;
return ;
}
inline void intersection(point a,point b,point c,point d){
dl a1=a.y-b.y,b1=b.x-a.x,c1=a.x*b.y-b.x*a.y;
dl a2=c.y-d.y,b2=d.x-c.x,c2=c.x*d.y-d.x*c.y;
dl x=(c1*b2-c2*b1)/(a2*b1-a1*b2);
dl y=(a2*c1-a1*c2)/(a1*b2-a2*b1);
printf("POINT %.2f %.2f\n",x,y);
return;
}
int main(){
puts("INTERSECTING LINES OUTPUT");
int t=read();
while(t--){
for(int i=;i<=;i++){
q[i].x=read();
q[i].y=read();
}
if(parallel_mag(getmag(q[],q[]),getmag(q[],q[]))){
if(!multiX(getmag(q[],q[]),getmag(q[],q[]))){
puts("LINE");
}else puts("NONE");
}else intersection(q[],q[],q[],q[]);
}
puts("END OF OUTPUT");
return ;
}

POJ1269:Intersecting Lines——题解的更多相关文章

  1. POJ1269:Intersecting Lines(判断两条直线的关系)

    题目:POJ1269 题意:给你两条直线的坐标,判断两条直线是否共线.平行.相交,若相交,求出交点. 思路:直线相交判断.如果相交求交点. 首先先判断是否共线,之后判断是否平行,如果都不是就直接求交点 ...

  2. POJ1269 Intersecting Lines[线段相交 交点]

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15145   Accepted: 66 ...

  3. poj1269 intersecting lines【计算几何】

    We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a p ...

  4. [poj1269]Intersecting Lines

    题目大意:求两条直线的交点坐标. 解题关键:叉积的运用. 证明: 直线的一般方程为$F(x) = ax + by + c = 0$.既然我们已经知道直线的两个点,假设为$(x_0,y_0), (x_1 ...

  5. POJ1269 Intersecting Lines 2017-04-16 19:43 50人阅读 评论(0) 收藏

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15478   Accepted: 67 ...

  6. POJ 1269 Intersecting Lines(计算几何)

    题意:给定4个点的坐标,前2个点是一条线,后2个点是另一条线,求这两条线的关系,如果相交,就输出交点. 题解:先判断是否共线,我用的是叉积的性质,用了2遍就可以判断4个点是否共线了,在用斜率判断是否平 ...

  7. Intersecting Lines(数学)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12844   Accepted: 57 ...

  8. ●POJ 1269 Intersecting Lines

    题链: http://poj.org/problem?id=1269 题解: 计算几何,直线交点 模板题,试了一下直线的向量参数方程求交点的方法. (方法详见<算法竞赛入门经典——训练指南> ...

  9. POJ 1269 - Intersecting Lines - [平面几何模板题]

    题目链接:http://poj.org/problem?id=1269 Time Limit: 1000MS Memory Limit: 10000K Description We all know ...

随机推荐

  1. HardcodedDebugMode

    xmlns:tools="http://schemas.android.com/tools" tools:ignore="HardcodedDebugMode"

  2. WEB安全基础之sql注入基础

    1.基础sql语句 注释 单行注释# %23--+ --加空格多行注释/**/ SELECT(VERSION()) SELECT(USER()) SELECT(database()) 查数据库 SEL ...

  3. linux部署MantisBT(三)部署MantisBT

    三.部署MantisBT 1.下载MantisBT https://www.mantisbt.org/download.php 2.将MantisBT安装包放在/apache/htdocs下并重命名为 ...

  4. NGUI组件整理总结

    一图流: 注意: private void RClickUI(Vector3 newPos) { this.gameObject.SetActive(true); this.transform.loc ...

  5. netty in action 笔记 二

    netty的数据容器 网络数据的基本单位大多为字节,Java NIO 提供了ByteBuffer 作为它的字节容器,但使用起来过于复杂和繁琐.在Netty中, ByteBuffer 替代品是ByteB ...

  6. 【C#】ArcFace2 视频人脸比对教程

    请允许我大言不惭,叫做教程,特希望各位能指正.哦,我用的是vs2017.了解更多详情可以访问虹软人工智能开放平台 一.准备工作 1.创建项目 2.添加EMGU.CV包 ,并设属性“复制到输出目录”为“ ...

  7. Windows10系统tensorflow-gpu安装

    准备工作 安装前请确保自己的显卡支持gpu加速,支持加速的gpu型号可在下面的链接中查询. https://www.geforce.com/hardware/technology/cuda/suppo ...

  8. LeetCode 95——不同的二叉搜索树 II

    1. 题目 2. 解答 以 \(1, 2, \cdots, n\) 构建二叉搜索树,其中,任意数字都可以作为根节点来构建二叉搜索树.当我们将某一个数字作为根节点后,其左边数据将构建为左子树,右边数据将 ...

  9. nodejs promise深度解析

    Promise本质上是一个容器,内部有一个执行函数,当promise对象New出来的时候,内部包裹的函数立即执行. V8引擎会将resolve和projeccted两个函数传递进来,resolved含 ...

  10. oraclize预言机资料

    oraclize预言机资料 智能合约如何可信的与外部世界交互: https://blog.csdn.net/sportshark/article/details/77477842 国外一篇讲得很详细的 ...