poj1269---直线位置关系
题目大意:给你8个点,也就是两条直线,让你判断他们的位置关系
代码如下:
#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define EPS 1e-8
struct Point
{
double x,y;
}a,b,c,d;
double xmult(Point p1,Point p2,Point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
} Point intersection(Point A, Point B, Point C, Point D)
{
//a1*x+b1*y=c1;a2*x+b2*y=c2;
Point ans;
double a1 = A.y-B.y;
double b1 = B.x-A.x;
double c1 = A.x*B.y-B.x*A.y;
double a2 = C.y-D.y;
double b2 = D.x-C.x;
double c2 = C.x*D.y-D.x*C.y;
double x = (b1*c2-b2*c1)/(a1*b2-a2*b1);
double y = (a2*c1-a1*c2)/(a1*b2-a2*b1);
ans.x=x,ans.y=y;
return ans;
}
int main()
{
//freopen("in.txt","r",stdin);
int T;
cin>>T;
printf("INTERSECTING LINES OUTPUT\n");
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y);
if(fabs(xmult(a,b,c))<=EPS&&fabs(xmult(a,b,d)<=EPS))
printf("LINE\n");//直线重合
else if((a.y-b.y)*(d.x-c.x)==(b.x-a.x)*(c.y-d.y))
printf("NONE\n");//直线平行
else
{
Point ans = intersection(a,b,c,d);
printf("POINT %.2f %.2f\n",ans.x,ans.y);
}
}
printf("END OF OUTPUT\n");
return 0;
}
poj1269---直线位置关系的更多相关文章
- POJ 2398 - Toy Storage 点与直线位置关系
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5439 Accepted: 3234 Descr ...
- 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(判断两直线位置关系)
题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...
- Intersecting Lines---poj1269(求两直线的位置关系)
题目链接:http://poj.org/problem?id=1269 题意:给你两条直线上的任意不同的两点,然后求两条直线的位置关系,如果相交于一点输出该点坐标; #include<iostr ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- Intersecting Lines (计算几何基础+判断两直线的位置关系)
题目链接:http://poj.org/problem?id=1269 题面: Description We all know that a pair of distinct points on a ...
- TOYS(计算几何基础+点与直线的位置关系)
题目链接:http://poj.org/problem?id=2318 题面: TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submiss ...
- poj 1269 判断直线的位置关系
题目链接 题意 判断两条直线的位置关系,重合/平行/相交(求交点). 直线以其上两点的形式给出(点坐标为整点). 思路 写出直线的一般式方程(用\(gcd\)化为最简), 计算\(\begin{vma ...
- 简单几何(直线位置) POJ 1269 Intersecting Lines
题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...
- Cupid's Arrow---hdu1756(判断点与多边形的位置关系 模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1756 题意:中文题,套模板即可: /* 射线法:判断一个点是在多边形内部,边上还是在外部,时间复杂度为 ...
随机推荐
- jmeter 常见问题汇总
文件读取中文乱码: 读取CSV文件,出现中文乱码,纠正方式如下: txt文件乱码 在用到该变量的请求上加上UTF-8 post请求 返回“ Content type 'application/x-ww ...
- 设计模式之Adapter设计模式
这个设计模式是我这两天刚学的,这儿算是我的读书笔记发布出来是供大家一起学习,后面有我自己的感悟,下面是我网上整理的 以下情况使用适配器模式 • 你想使用一个已经存在的类,而它的接口不符合你的需求. • ...
- android 混淆文件proguard.cfg详解 (转载)
-injars androidtest.jar[jar包所在地址] -outjars out[输出地址] -libraryjars 'D:\android-sdk-windows\platf ...
- PTA第五次作业
#include<stdio.h> #include<math.h> int main () { int n,m,i,j,a; scanf("%d",&am ...
- Part 6 - Class-Based Views(21-26)
https://github.com/sibtc/django-beginners-guide/tree/v0.6-lw urlpatterns = [ views.PostUpdateView.as ...
- mybatis后台中传参到sql语句中,使用@Param注解
- UVa 11292 Dragon of Loowater (水题,排序)
题意:有n个条龙,在雇佣勇士去杀,每个勇士能力值为x,只能杀死头的直径y小于或等于自己能力值的龙,只能被雇佣一次,并且你要给x赏金,求最少的赏金. 析:很简单么,很明显,能力值高的杀直径大的,低的杀直 ...
- No cache or cacheManager properties have been set. Authorization cache cannot be obtained.
20235 [http-bio-8080-exec-10] INFO o.a.shiro.realm.AuthorizingRealm - No cache or cacheManager prope ...
- day8 异常处理
异常和错误 part1:程序中难免出现错误,而错误分成两种 1.语法错误(这种错误,根本过不了python解释器的语法检测,必须在程序执行前就改正) 2.逻辑错误(逻辑错误) part2:什么是异常 ...
- (最大上升子序列) Super Jumping! Jumping! Jumping! -- hdu -- 1087
http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit:1000MS ...