POJ 1269 Intersecting Lines(线段相交,水题)
id=1269" rel="nofollow">Intersecting Lines
大意:给你两条直线的坐标,推断两条直线是否共线、平行、相交。若相交。求出交点。
思路:线段相交推断、求交点的水题。没什么好说的。
struct Point{
double x, y;
} ;
struct Line{
Point a, b;
} A, B;
double xmult(Point p1, Point p2, Point p)
{
return (p1.x-p.x)*(p2.y-p.y)-(p1.y-p.y)*(p2.x-p.x);
}
bool parallel(Line u, Line v)
{
return zero((u.a.x-u.b.x)*(v.a.y-v.b.y)-(v.a.x-v.b.x)*(u.a.y-u.b.y));
}
Point intersection(Line u, Line v)
{
Point ret = u.a;
double t = ((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));
ret.x += (u.b.x-u.a.x)*t, ret.y += (u.b.y-u.a.y)*t;
return ret;
}
int T;
void Solve()
{
scanf("%d", &T);
printf("INTERSECTING LINES OUTPUT\n");
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &A.a.x, &A.a.y, &A.b.x, &A.b.y, &B.a.x, &B.a.y, &B.b.x, &B.b.y);
if(parallel(A, B) && zero(xmult(A.a, B.a, B.b)))
{
printf("LINE\n");
}
else if(parallel(A, B))
{
printf("NONE\n");
}
else
{
Point t = intersection(A, B);
printf("POINT %.2f %.2f\n", t.x, t.y);
}
}
printf("END OF OUTPUT\n");
}
POJ 1269 Intersecting Lines(线段相交,水题)的更多相关文章
- poj 1269 Intersecting Lines(直线相交)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8637 Accepted: 391 ...
- 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 - [平面几何模板题]
题目链接:http://poj.org/problem?id=1269 Time Limit: 1000MS Memory Limit: 10000K Description We all know ...
- 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 直线与直线相交
题意: 判断直线间位置关系: 相交,平行,重合 include <iostream> #include <cstdio> using namespace std; str ...
- poj 1269 Intersecting Lines——叉积求直线交点坐标
题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...
- poj 1269 Intersecting Lines
题目链接:http://poj.org/problem?id=1269 题目大意:给出四个点的坐标x1,y1,x2,y2,x3,y3,x4,y4,前两个形成一条直线,后两个坐标形成一条直线.然后问你是 ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
随机推荐
- Android开发——常用ADB命令的使用
ADB全称Android Debug Bridge, 是android sdk里的一个工具, 用这个工具可以直接操作管理android模拟器或者真实的andriod设备.它的功能如下: 运行设备的sh ...
- Fidder详解-抓取HTTPS清求(Web/App)抓包分析(靠谱篇)
为什么要学Fidder抓包? 学习接口,必须要学http协议,不要求您对协议的掌握有多深.只是希望你能够了解什么是协议.协议的报文.状态码等等!本文通过抓包工具Fidder带你进入接口的大门.我们通过 ...
- bzoj1202:[HNOI2005]狡猾的商人 【并查集】
Description 刁姹接到一个任务,为税务部门调查一位商人的账本,看看账本是不是伪造的.账本上记录了n个月以来的收入情况,其中第i 个月的收入额为Ai(i=1,2,3...n-1,n), .当 ...
- To_Date函数用法
spl> select * from emp where dates between to_date('2007-06-12 10:00:0 ...
- CodeForces 592D Super M
先把没用的边去掉,求出包含m个点的最小树.然后求出最小树的直径就可以得到答案了. #include <cstdio> #include <cstring> #include & ...
- 免费SSL申请
https://letsencrypt.org/ https://letsencrypt.org/docs/client-options/ ACMESharp (.NET, PowerShell) w ...
- Substrings--poj1226(字符串)
Description You are given a number of case-sensitive strings of alphabetic characters, find the larg ...
- [Bzoj4182]Shopping(点分治)(树上背包)(单调队列优化多重背包)
4182: Shopping Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 374 Solved: 130[Submit][Status][Disc ...
- SyntaxError: expected expression, got '<'异常错误
引入jQuery文件,浏览器报SyntaxError: expected expression, got '<'错误,但是jQuery文件可以在网络一栏看到,最后检查是springMVC定义的拦 ...
- EF关联
public CustomerMap() { this.ToTable("Customer"); this.HasKey(c => c.Id); this.Property( ...