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.前言 ...
随机推荐
- 说一下acad的bug及问题
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk. ...
- CDH中如何升级Spark
公司平时使用的CDH版本的hadoop生态,spark任务是基于yarn来管理的,而不是基于原生的spark master slave集群管理. 因此任务的大致启动模式是: 如果是Cluster模式: ...
- 脚本中 if 判断细节
if [[ $1 == "fedora" ]];then echo "redhat" elif [[ $1 == "redhat" ]];t ...
- ajax post 请求发送 json 字符串
$.ajax({ // 请求方式 type:"post", // contentType contentType:"application/json", // ...
- cnetos6上实现nfs共享
利用空余时间,做个nfs共享实验,岂不美滋滋!!! 系统测试环境: 主机ip 系统 主机名(服务) 192.168.241.130 centos6.5 hadoop1(nfs-sr ...
- 读书笔记--SQL必知必会--常用MySQL(MariaDB)命令及示例
DBMS信息 显示DBMS的版本 select version(); 显示DBMS状态 status; 显示DBMS资源状态 show status; 显示DBMS支持的权限 show privile ...
- iOS-button利用block封装按钮事件【runtime 关联】
用block封装最常用的就是网络请求的回调,其实也可以结合category封装button的按钮事件,同时利用runtime的对象关联: UIButton+wkjButton.h 文件 #import ...
- karma 启动提示PhantomJS not found on PATH
Karma 介绍:是由AngularJS团队开发的测试执行过程管理实用工具,帮助开发人员在不同的浏览器中执行测试. 一般搭配PhantomJS作为浏览器启动器.PhantomJS是一个非主流的Webk ...
- WebForm - cookie赋值乱码问题
cookie的值为中文时候,取cookie的值会出现乱码 解决办法:存取cookie时候先解码和编码 存cookie,进行编码: cookie.Value = HttpUtility.UrlEncod ...
- odoo开发笔记-tree列表视图拖拽排序
odoo列表tree视图 拖拽排序 实现效果: 实现方式: 模型中定义字段: class CusYourModel(models.Model): """ 你的模型 &qu ...