poj 1269 Intersecting Lines(直线相交)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 8637 | Accepted: 3915 |
Description
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
Source
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define eps 1e-8
#define oo 100000000
#define pi acos(-1)
struct point
{
double x,y;
point(double _x = 0.0,double _y = 0.0)
{
x =_x;
y =_y;
}
point operator -(const point &b)const
{
return point(x - b.x, y - b.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;
}
}p[]; double dis(point a,point b)//两点之间的距离
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} int dcmp(double a)//判断一个double型的符号
{
if(fabs(a)<eps)return ;
if(a>)return ;
else return -;
} int isxiangjiao(point a,point b,point c,point d)//判断直线相交,重合,平行!!!
{
point aa,bb,cc,dd;
aa=b-a;
bb=d-c;
if(dcmp(aa^bb)!=)return ;//相交
else
{
aa=a-d;
bb=b-c;
cc=a-c;
dd=b-d;
if(dcmp(aa^bb)!=||dcmp(cc^dd)!=)return ;//平行
else return ;//重合
}
} point getjiaodian(point p,point v,point q,point w)//参数方程,v,w都为方向向量,p,q,为两直线上的点,求交点
{
point u;
u=p-q;
double t=(w^u)/(v^w);
v.x=t*v.x;v.y=t*v.y;
return p+v;
} int main()
{
int T,i,j;
scanf("%d",&T);
printf("INTERSECTING LINES OUTPUT\n");
while(T--)
{
for(i=;i<=;i++)scanf("%lf%lf",&p[i].x,&p[i].y); if(isxiangjiao(p[],p[],p[],p[])==)
{
point ans,v,w,q;
v=p[]-p[];
w=p[]-p[];
ans=getjiaodian(p[],v,p[],w);
printf("POINT %.2f %.2f\n",ans.x,ans.y);
} if(isxiangjiao(p[],p[],p[],p[])==)printf("NONE\n");//平行 if(isxiangjiao(p[],p[],p[],p[])==)printf("LINE\n");//重合
}
printf("END OF OUTPUT\n");
return ;
}
poj 1269 Intersecting Lines(直线相交)的更多相关文章
- 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(直线相交判断,求交点)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8342 Accepted: 378 ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- poj 1269 Intersecting Lines——叉积求直线交点坐标
题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...
- 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(线段相交,水题)
id=1269" rel="nofollow">Intersecting Lines 大意:给你两条直线的坐标,推断两条直线是否共线.平行.相交.若相交.求出交点. ...
随机推荐
- B - Sumdiv(第三周)
B - Sumdiv 题目链接:https://vjudge.net/contest/154063#problem/B 题意: 求A^B的所有约数(即因子)之和,并对其取模 9901再输出. 解题思路 ...
- POJ 1434 Fill the Cisterns! (模拟 or 二分)
Fill the Cisterns! 题目链接: http://acm.hust.edu.cn/vjudge/contest/129783#problem/F Description During t ...
- bat语法
注释 :: 注释无回显 rem 注释有回显 关闭和开启回显 :: 关闭回显 @echo off echo abc :: 开启回显 echo on echo 查看命令帮助说明 rd /? 目录操作 创建 ...
- 洛谷P4124 手机号码
传送 这题也就是条件限制多了点,也没有别的,套板子就好了 注意这里没有前导零,所以第一位是从1开始填 看注释叭 #include<iostream> #include<cstdio& ...
- 与Pig相似,Hive是一种MapReduce上的抽象工具(除非使用新的执行引擎)
Hive隐藏了后面的MapReduce任务 EXPLAIN sql: 分析查询计划.
- iOS即时通讯之CocoaAsyncSocket源码解析二
原文 前言 本文承接上文:iOS即时通讯之CocoaAsyncSocket源码解析一 上文我们提到了GCDAsyncSocket的初始化,以及最终connect之前的准备工作,包括一些错误检查:本机地 ...
- 九、MySQL报错( (1292, u"Truncated incorrect DOUBLE value: '424a000000066'") result = self._query(query))
1.数据库sql语句:SELECT seat_id FROM netsale_order_seat os join netsale_order nor on os.order_code=nor.ord ...
- 爬虫解析库xpath
# xpath简介 XPath即为XML路径语言(XML Path Language),它是一种用来确定XML文档中某部分位置的语言.用于在 XML 文档中通过元素和属性进行导航. XPath基于XM ...
- docker远程访问TLS证书认证shell
docker开启远程访问端口,防止非法访问 配置证书认证 配置防火墙或安全策略 #!/bin/bash # docker.tls.sh # 环境centos 7 ,root # 创建 Docker T ...
- js(javascript)取float型小数点后两位数的方法
以下我们将为大家介绍 JavaScript 保留两位小数的实现方法:四舍五入以下处理结果会四舍五入: ? 1 2 var num =2.446242342; num = num.toFixed(2); ...