用的是初中学的方法

#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 判断两直线关系的更多相关文章

  1. poj 1269 Intersecting Lines(判断两直线关系,并求交点坐标)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12421   Accepted: 55 ...

  2. POJ 1269 Intersecting Lines (判断直线位置关系)

    题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...

  3. POJ 1269 Intersecting Lines(判断两直线位置关系)

    题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...

  4. 判断两条直线的位置关系 POJ 1269 Intersecting Lines

    两条直线可能有三种关系:1.共线     2.平行(不包括共线)    3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...

  5. POJ 1269 Intersecting Lines【判断直线相交】

    题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...

  6. POJ 1269 Intersecting Lines(直线相交判断,求交点)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8342   Accepted: 378 ...

  7. poj 1269 Intersecting Lines

    题目链接:http://poj.org/problem?id=1269 题目大意:给出四个点的坐标x1,y1,x2,y2,x3,y3,x4,y4,前两个形成一条直线,后两个坐标形成一条直线.然后问你是 ...

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

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

  9. poj 1269 Intersecting Lines——叉积求直线交点坐标

    题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...

随机推荐

  1. 强哥PHP学习笔记

    1.php的代码,必须放在.php的文件中,php代码必须写在<?php ?>之间. 2.//单行注释 /* 多行注释 */ 3.默认首页index.php index.html inde ...

  2. tar -zxvf file.tar.gz //解压tar.gz

    http://apps.hi.baidu.com/share/detail/37384818 download ADT link http://dl.google.com/android/ADT-0. ...

  3. Centos7 cache/buff过高处理方法

    Centos7 cache/buff过高处理方法   kevinxliu关注0人评论36799人阅读2018-07-26 10:09:59   当linux运行久点,会产生很多不必要的cache或者b ...

  4. Mysql_源码包安装详细过程

    一.mysql安装 1.二进制安装 2.源码包安装 3.rpm包安装 1.源码包安装 1)上传或下载源码包 [root@db02 ~]# rz mysql-5.6.46.tar.gz 2)安装依赖 由 ...

  5. OpenStack neutron vlan 模式下的网络包流向

    时间:2015-01-15 18:09:41 1.什么是Neutron? Neutron是OpenStack的network project ,是NaaS(networking-as-a-servic ...

  6. mysql3_pymysql

    python数据库编程 1.pyshon数据库接口(python DB-API) 1.为开发人员提供的数据库应用编程接口 2.python支持的数据库服务软件 mysql,oracle,sql_ser ...

  7. 代码动态更换MeshRenderer的材质Materials

    public class metrailstest : MonoBehaviour { Material[] m; Material i; public Material[] n; int index ...

  8. Python+Selenium学习笔记10 - send_keys上传文件

    在火狐浏览器上传文件 上传前,同一个HTML文件在火狐和Edge浏览器显示有些不同 这是Firefox浏览器的显示 这是Edge浏览器 上传后 1 # coding = utf-8 2 3 from ...

  9. 手把手带你快速入门jQuery(视频|资料,建议收藏!)

    jQuery是什么? jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架). jQuery设计的宗旨是 ...

  10. NVIDIA DeepStream 5.0构建智能视频分析应用程序

    NVIDIA DeepStream 5.0构建智能视频分析应用程序 无论是要平衡产品分配和优化流量的仓库,工厂流水线检查还是医院管理,要确保员工和护理人员在照顾病人的同时使用个人保护设备(PPE),就 ...