POJ1269(KB13-D 计算几何)
Intersecting Lines
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 16681 | Accepted: 7192 |
Description
Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000.
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
//2017-08-30
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip> using namespace std; const int N = ;
const double EPS = 1e-; //三态函数
int sgn(double x){
if(fabs(x) < EPS)return ;
if(x < )return -;
else return ;
} struct Point{
double x, y;
Point(){}
Point(double _x, double _y):x(_x), y(_y){}
Point(const Point &p):x(p.x), y(p.y){}
//a-b为向量ba
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;
}
}; struct Line{
Point a, b;
Line(){}
Line(Point _a, Point _b):a(_a), b(_b){}
//判断两直线关系
//input:两直线
//output:pair<int, Point> first == 0 表示直线重合
// first == 1 表示两直线平行
// first == 2 表示两直线相交,second 为交点
pair<int, Point> operator & (const Line &line) const{
Point res = a;
if(sgn((a-b)^(line.a-line.b)) == ){
if(sgn((a-line.b)^(line.a-line.b)) == )
return make_pair(, res);
else return make_pair(, res);
}
double t = ((a-line.a)^(line.a-line.b))/((a-b)^(line.a-line.b));
res.x += (b.x-a.x)*t;
res.y += (b.y-a.y)*t;
return make_pair(, res);
}
}seg[N]; int n;
int main()
{
std::ios::sync_with_stdio(false);
//freopen("inputD.txt", "r", stdin);
int T;
cin>>T;
cout<<"INTERSECTING LINES OUTPUT"<<endl;
while(T--){
Line l1, l2;
cin>>l1.a.x>>l1.a.y>>l1.b.x>>l1.b.y;
cin>>l2.a.x>>l2.a.y>>l2.b.x>>l2.b.y;
pair<int, Point> res = l1 & l2;
cout.setf(ios::fixed);
if(res.first == )
cout<<"LINE"<<endl;
else if(res.first == )
cout<<"NONE"<<endl;
else
cout<<setprecision()<<"POINT "<<res.second.x<<" "<<res.second.y<<endl;
}
cout<<"END OF OUTPUT"<<endl; return ;
}
POJ1269(KB13-D 计算几何)的更多相关文章
- poj1269计算几何直线和直线的关系
We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a p ...
- poj1269 intersecting lines【计算几何】
We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a p ...
- 计算几何——直线交点poj1269
求直线交点还是要推一个公式的.. 见博客https://blog.csdn.net/u013050857/article/details/40923789 还要学一下向量的定点比分法 另外poj精度好 ...
- ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)
POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...
- HDU 2202 计算几何
最大三角形 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- ACM 计算几何中的精度问题(转)
http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...
- hdu 2393:Higher Math(计算几何,水题)
Higher Math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- [知识点]计算几何I——基础知识与多边形面积
// 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxaq.html 1.前言 ...
随机推荐
- 2018-2019-2 20175230 实验三《Java面向对象程序设计》实验报告
目录 实验三 实验三 敏捷开发与XP实践 实验内容 实验要求 实验步骤 (一) 编码标准 (二)敏捷开发与XP (三)敏捷开发与XP 实验体会 实验三 实验三 敏捷开发与XP实践 实验内容 1.XP基 ...
- C++ 执行Windows cmd命令
#include <windows.h> #include <iostream> #include <cstdio> using namespace std; vo ...
- 微信小程序实现给循环列表点击添加类(单项和多项)
在微信小程序里面没有DOM对象, 不能操作DOM. 所有的操作通过数据来实现,下面主要实现了给循环列表点击添加类的操作 一.单项 目标需求:实现下图,给点击的view增加类,每次只能选择一个. 主要思 ...
- Yarn 资源调度框架
Yarn 资源调度框架 实现对资源的细粒度封装(cpu,内存,带宽) 此外,还可以通过yarn协调多种不同计算框架(MR,Spark) 概述 Apache Hadoop ...
- 【并发】1、关于线程的几种状态&关于yield的理解
最近在看disruptor源码,在获取ringbuffer的下一个序列的时候,disruptor有几种等待策略,其中有YieldingWaitStrategy类,是使用java的Thread.yiel ...
- [翻译] Trident-ML:基于storm的实时在线机器学习库
最近在看一些在线机器学习的东西,看到了trident-ml, 觉得比较有意思,就翻译了一下,方便有兴趣的读者学习. 本文为作者(掰棒子熊)翻译自https://github.com/pmerienne ...
- socket练习:FTP
FTP 练习收获: 1,类型转换 2,进度条实现: 3,print 输出不换行的方法: print输出 不换行的方法: 方法一: import sys sys.stdout.write(" ...
- c++获取随机数
方法一: 使用 rand 函数可以获取,如下. 随机数大小是在0到RAND_MAX,值为2147483647,它是在stdlib中定义的,如果我们希望在某个范围内,可以使用 % 结合 / 来实现. 但 ...
- Spring Boot + Redis
启动redis docker run --name redisServer -P -d redis redis自带客户端,启动客户端 docker run -it --link redisServer ...
- FineBI学习系列之FineBI的ETL处理(图文详解)
不多说,直接上干货! 这是来自FineBI官网提供的帮助文档 http://help.finebi.com/http://help.finebi.com/doc-view-48.html 目录: 1. ...