poj 1269(两条直线交点)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 13481 | Accepted: 5997 |
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
first line contains an integer N between 1 and 10 describing how many
pairs of lines are represented. The next N lines will each contain eight
integers. These integers represent the coordinates of four points on
the plane in the order x1y1x2y2x3y3x4y4. Thus each of these input lines
represents two lines on the plane: the line through (x1,y1) and (x2,y2)
and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always
distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).
Output
should be N+2 lines of output. The first line of output should read
INTERSECTING LINES OUTPUT. There will then be one line of output for
each pair of planar lines represented by a line of input, describing how
the lines intersect: none, line, or point. If the intersection is a
point then your program should output the x and y coordinates of the
point, correct to two decimal places. The final line of output should
read "END OF 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 计算几何真的不容易AC。。。模板代码。。函数名自己用百度翻译起的。。
#include <iostream>
#include <cstdio>
#include <string.h>
#include <math.h>
#include <algorithm> using namespace std;
const double eps = 1e-;
const int N = ;
struct Point
{
double x,y;
} ;
struct Line{
Point a,b;
};
///叉积
double mult(Point a, Point b, Point c)
{
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
///计算两条直线的交点
Point intersection(Point a,Point b,Point c,Point d){
Point p = a;
double t = ((a.x-c.x)*(c.y-d.y)-(a.y-c.y)*(c.x-d.x))/((a.x-b.x)*(c.y-d.y)-(a.y-b.y)*(c.x-d.x));
p.x +=(b.x-a.x)*t;
p.y +=(b.y-a.y)*t;
return p;
}
double parallel(Point a,Point b,Point c,Point d){ ///判断平行
return fabs((a.x-b.x)*(c.y-d.y)-(a.y-b.y)*(c.x-d.x));
}
int main()
{
int tcase;
scanf("%d",&tcase);
printf("INTERSECTING LINES OUTPUT\n");
while(tcase--){
Line l1,l2;
scanf("%lf%lf%lf%lf",&l1.a.x,&l1.a.y,&l1.b.x,&l1.b.y);
scanf("%lf%lf%lf%lf",&l2.a.x,&l2.a.y,&l2.b.x,&l2.b.y);
if(parallel(l1.a,l1.b,l2.a,l2.b)<eps){ ///两直线平行
if(fabs(mult(l1.b,l2.a,l1.a))<eps){ ///判断共线
printf("LINE\n");
}
else printf("NONE\n");
}
else{
Point p = intersection(l1.a,l1.b,l2.a,l2.b);
printf("POINT %.2lf %.2lf\n",p.x,p.y);
} }
printf("END OF OUTPUT\n");
return ;
}
poj 1269(两条直线交点)的更多相关文章
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- 计算两条直线的交点(C#)
PS:从其他地方看到的源码是有问题的.下面是修正后的 /// <summary> /// 计算两条直线的交点 /// </summary> /// <param name ...
- C++ 根据两点式方法求直线并求两条直线的交点
Line.h #pragma once //Microsoft Visual Studio 2015 Enterprise //根据两点式方法求直线,并求两条直线的交点 #include"B ...
- POJ1269:Intersecting Lines(判断两条直线的关系)
题目:POJ1269 题意:给你两条直线的坐标,判断两条直线是否共线.平行.相交,若相交,求出交点. 思路:直线相交判断.如果相交求交点. 首先先判断是否共线,之后判断是否平行,如果都不是就直接求交点 ...
- 求空间内两条直线的最近距离以及最近点的坐标(C++)
关键词:空间几何 用途:总有地方会用到吧 文章类型:C++函数展示 @Author:VShawn(singlex@foxmail.com) @Date:2016-11-19 @Lab: CvLab20 ...
- 两条直线(蓝桥杯)二分枚举+RMQ
算法提高 两条直线 时间限制:1.0s 内存限制:256.0MB 问题描述 给定平面上n个点. 求两条直线,这两条直线互相垂直,而且它们与x轴的夹角为45度,并且n个点中离这两条 ...
- CodeForces - 961D:Pair Of Lines (几何,问两条直线是否可以覆盖所有点)
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordin ...
- C# 判断两条直线距离
本文告诉大家获得两条一般式直线距离 一般式的意思就是 Ax+By+C=0" role="presentation">Ax+By+C=0Ax+By+C=0 如果有两个 ...
- 2018-7-31-C#-判断两条直线距离
title author date CreateTime categories C# 判断两条直线距离 lindexi 2018-07-31 14:38:13 +0800 2018-05-08 10: ...
随机推荐
- Mac上基于hexo+GitHub搭建个人博客(一)
原文地址: http://fanjiajia.cn/2018/11/23/Mac%E4%B8%8A%E5%9F%BA%E4%BA%8Ehexo+GitHub%E6%90%AD%E5%BB%BA%E4% ...
- lintcode-106-排序列表转换为二分查找树
106-排序列表转换为二分查找树 给出一个所有元素以升序排序的单链表,将它转换成一棵高度平衡的二分查找树 样例 标签 递归 链表 思路 类似于二分查找,每次将链表二分,中间节点作为根节点,在建立左子树 ...
- Redis能做什么?不能做什么?
https://blog.csdn.net/u014229282/article/details/81174202 最近阅读了<redis设计与实现>,这是一本比较枯燥的书,毕竟涉及到re ...
- vue2.0中vue-router使用总结
#在vue-cli所创建的项目中使用 进入到项目的目录后使用 npm install vue-router --save 安装vue-router,同时保存在webpack.Json配置文件中,然 ...
- 批处理中的IF详解
在CMD使用IF /?打开IF的系统帮助会发现IF有3种基本的用法! 第一种用法:IF [NOT] ERRORLEVEL number command 这种用法现在很少用了,因为它需要使用到CHOIC ...
- js表单验证工具包
常用的js表单验证方法大全 /* 非空校验 : isNull() 是否是数字: isNumber(field) trim函数: trim() lTrim() rTrim() 校验字符串是否为空: ch ...
- Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记
夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...
- SetLocalTime设置本地时间
/***************************************************************** 函数名:EnableSetTimePriviledge 功 能:开 ...
- 洛谷 P2486 [SDOI2011]染色/bzoj 2243: [SDOI2011]染色 解题报告
[SDOI2011]染色 题目描述 给定一棵有n个节点的无根树和m个操作,操作有2类: 1.将节点a到节点b路径上所有点都染成颜色c: 2.询问节点a到节点b路径上的颜色段数量(连续相同颜色被认为是同 ...
- git使用笔记(九)操作原理
By francis_hao Nov 27,2016 参考[1]的一张图已经把git的基本原理描述的很清楚了,如下: 下面以实例演示其过程,需要用到两个命令cat-file和ls-fil ...