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 大意:给你两条直线的坐标,推断两条直线是否共线.平行.相交.若相交.求出交点. ...
随机推荐
- Android 输入法截取key优先于view
为了验证编写了个例子 首先是输入法 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 public class RemoteKeyboard exte ...
- 清北学堂2019NOIP提高储备营DAY4
今天只有一上午,讲的东西不多,这里就整理一下高精的东西,数论部分请见my blog 高精度: 先讲一讲进制问题:十进制的二进制表示:以10为例, 10的二进制表示为1010 10的三进制表示为101 ...
- selinux 了解2
凡是对内核级, 如selinux的修改, 不只是对软件, 程序的修改, 那么修改之后都要重新启动. 针对windows下的截图, 像linux下的screenshot截图那样设置快捷键 shift+s ...
- CGI FastCGI WSGI 解析
我们将服务端程序分为了web服务器和应用程序服务器. web服务器是用于处理HTML文件,让客户可以通过浏览器进行访问.主流的有apache,IIS,nginx,lghttpd等. 应用服务器处理业务 ...
- java SimpleDateFormat setLenient用法
参考博客:https://www.cnblogs.com/my-king/p/4276577.html SimpleDateFormat.setLenient(true) : 默认值true,不严格解 ...
- 手把手教您在 Windows Server 2019 上使用 Docker
配置 Windows 功能 要运行容器,您还需要启用容器功能 Install-WindowsFeature -Name Containers 在 Window Server 2019 上安装 Dock ...
- 合并流SequenceInputStream
合并流 SequenceInputStream概述 SequenceInputStream类可以将多个输入流串流在一起,合并为一个输入流,因次,该流也称为合并流. SequenceInputStrea ...
- DataFrame 结构
概念 DataFrame 是表格型的数据结构 ,DataFrame 本质上可以看做是由series 组成的字典, 它既有行索引,也有列索引. 它并不是列表,也不是字典,.
- python实现建立tcp通信
实现代码如下: #tcp协议通信import socketclass TcpConnect: def get_tcp(self,ip,port,message): #实例化一个基于tcp的socket ...
- 内网渗透 - 提权 - Windows
MS提权 MS16- MS16- 提权框架 Sherlock 信息收集 ifconfig -a cat /etc/hosts arp -a route -n cat /proc/net/* ping扫 ...