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 大意:给你两条直线的坐标,推断两条直线是否共线.平行.相交.若相交.求出交点. ...
随机推荐
- LUOGU P2569 [SCOI2010]股票交易(单调队列优化dp)
传送门 解题思路 不难想一个\(O(n^3)\)的\(dp\),设\(f_{i,j}\)表示第\(i\)天,手上有\(j\)股的最大收益,因为这个\(dp\)具有单调性,所以\(f_i\)可以贪心的直 ...
- hdu3714 Error Curves
题目: Error Curves Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- Last Defence
Given two integers A and B. Sequence S is defined as follow: • S0 = A •S1 = B • Si = |Si−1 − Si−2| f ...
- 官方文档翻译-Today
原文链接: Today 最后更新:2017-02-18 译文: 应用的今日视图扩展被称作小部件.小部件为用户提供快速访问重要信息的入口.例如,用户打开今日视图实时查看股票价格或天气情况,查看今天的日程 ...
- hashcode native
hashcode Java中的hashCode方法就是根据一定的规则将与对象相关的信息(比如对象的存储地址,对象的字段等)映射成一个数值,这个数值称作为散列值. 在设计hashCode方法和equal ...
- js方法返回多值如何取值demo
js方法返回,如何取值?下面demo两种方法 new array 和 json 返回值 取值示例. 方法一: new array <html> <head> <meta ...
- error: ‘xxx’ does not name a type
error: ‘TPlanMgr’ does not name a type 两个头文件相互应用会导致一个头文件你的类型无定义问题.
- 开源认证组件汇总 Kerberos和CAS
一.Kerberos 1.Kerberos原理和工作机制 概述:Kerberos的工作围绕着票据展开,票据类似于人的驾驶证,驾驶证标识了人的信息,以及其可以驾驶的车辆等级. 1.1 客户机初始验证 ...
- 关于Java泛型实现原理的思考与一般用法示例总结
面向对象的一个重要目标是对代码重用的支持.支持这个目标的一个重要机制就是泛型机制.在1.5版本之前,java并没有直接支持泛型实现,泛型编程的实现时通过使用继承的一些基本概念来完成的. 这种方式的局限 ...
- 【洛谷P1036 选数】
这个题显然用到了深搜的内容 让我们跟着代码找思路 #include<bits/stdc++.h>//万能头 ],ans; inline bool prime(int n)//最简单的判定素 ...