poj 1269 直线间的关系
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 9360 | Accepted: 4210 |
Description
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
- #include <iostream>
- #include <cmath>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- struct Point{
- double x,y;
- Point(){}
- Point(double x,double y):x(x),y(y){}
- };
- struct Line{
- Point a,b;
- };
- typedef Point Vector;
- Vector operator +(Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
- Vector operator -(Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}
- Vector operator *(Vector A,double p){return Vector(A.x*p,A.y*p);}
- Vector operator /(Vector A,double p){return Vector(A.x/p,A.y/p);}
- bool operator < (const Point &a,const Point &b)
- {
- return a.x<b.x||(a.x==b.x&&a.y<b.y);
- }
- const double eps=1e-10;
- int dcmp(double x)
- {
- if(fabs(x)<eps) return 0;
- else return x<0?-1:1;
- }
- bool operator == (const Point &a,const Point &b){
- return (dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0);
- }
- double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//点积
- double Length(Vector A){return sqrt(Dot(A,A));}//向量长度
- //两向量的夹角
- double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));}
- double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}//叉积
- Point GetLineIntersection(Point p,Vector v,Point q,Vector w)
- {
- Vector u=p-q;
- double t=Cross(w,u)/Cross(v,w);
- return p+v*t;
- }
- double DistanceToLine(Point P,Point A,Point B)
- {
- Vector v1=B-A,v2=P-A;
- return fabs(Cross(v1,v2)) / Length(v1);
- }
- void judge(Line a,Line b)
- {
- Point p;
- if(dcmp(Cross(a.a-a.b,b.a-b.b)) == 0)
- {
- if(dcmp(DistanceToLine(b.a,a.a,a.b)) == 0)
- {
- printf("LINE\n");return ;
- }
- else
- {
- printf("NONE\n");return ;
- }
- }
- else
- {
- p=GetLineIntersection(a.a,a.a-a.b,b.a,b.a-b.b);
- printf("POINT %.2lf %.2lf\n",p.x,p.y);
- return ;
- }
- }
- int main()
- {
- int n,i;
- Line L1,L2;
- while(~scanf("%d",&n))
- {
- printf("INTERSECTING LINES OUTPUT\n");
- for(i=0;i < n;i++)
- {
- 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);
- judge(L1,L2);
- }
- printf("END OF OUTPUT\n");
- }
- return 0;
- }
poj 1269 直线间的关系的更多相关文章
- POJ 1269 (直线求交)
Problem Intersecting Lines (POJ 1269) 题目大意 给定两条直线,问两条直线是否重合,是否平行,或求出交点. 解题分析 主要用叉积做,可以避免斜率被0除的情况. 求交 ...
- POJ 1269 (直线相交) Intersecting Lines
水题,以前总结的模板还是很好用的. #include <cstdio> #include <cmath> using namespace std; ; int dcmp(dou ...
- POJ 1269 - Intersecting Lines 直线与直线相交
题意: 判断直线间位置关系: 相交,平行,重合 include <iostream> #include <cstdio> using namespace std; str ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- 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 ...
- poj 1269 判断直线的位置关系
题目链接 题意 判断两条直线的位置关系,重合/平行/相交(求交点). 直线以其上两点的形式给出(点坐标为整点). 思路 写出直线的一般式方程(用\(gcd\)化为最简), 计算\(\begin{vma ...
- POJ 1269 /// 判断两条直线的位置关系
题目大意: t个测试用例 每次给出一对直线的两点 判断直线的相对关系 平行输出NODE 重合输出LINE 相交输出POINT和交点坐标 1.直线平行 两向量叉积为0 2.求两直线ab与cd交点 设直线 ...
- 直线相交 POJ 1269
// 直线相交 POJ 1269 // #include <bits/stdc++.h> #include <iostream> #include <cstdio> ...
随机推荐
- ubuntu kylin 13.10 无法安装ia32-libs解决方案
1.安装 Synaptic 2.sudo apt-get install synaptic 3.进入synaptic ,设置->软件库 4.点击 其他软件->添加 5.输入“deb ht ...
- Codeforces Round #318 (Div. 2) C Bear and Poker (数学)
简单题,求一下所有数的2和3的幂是任意调整的,把2和3的因子除掉以后必须相等. 求lcm,爆了long long.我得好好反省一下,对连乘不敏感 #include<bits/stdc++.h&g ...
- php接受axios数据
var params = { username: 'admin', password: '123456' } axios.post('test.php', params).then(res => ...
- firstElectron_web5 安装
小娜 搜 cmd 右键 管理员运行 1.装全局 这样 不用每次都下载 因为包挺大的 还有用cnpm 要不太慢 cnpm install electron --save-dev --save-exact ...
- Vue之父子组件的通信
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- No-12.函数进阶
函数进阶 目标 函数参数和返回值的作用 函数的返回值 进阶 函数的参数 进阶 递归函数 01. 函数参数和返回值的作用 函数根据 有没有参数 以及 有没有返回值,可以 相互组合,一共有 4 种 组合形 ...
- PHP 腾讯云cos使用之我见
因为某些人的原因,本文从新改名发布一遍. 原名称:tp5 -- 腾讯云cos简单使用 原文链接:https://www.cnblogs.com/YFYQ/p/10840050.html 因项目需要,本 ...
- shell脚本,一个shell的启动流程。
#一个shell的启动流程 #shell有一些变量,叫做环境变量,这些变量是可以继承的, #比如父shell有$UID,子shell也可以有,而且继承父shell的. #正常我们声明一个变量,a=,在 ...
- 什么是二维数组?二维遍历?Java二维数组制作图片迷宫 使用如鹏游戏引擎制作窗口界面 附带压缩包下载,解压后双击start.bat启动
什么是二维数组? 数组当中放的还是数组 int [][] arr=new int[3][2]; 有3个小箱子,每个箱子2个格子. 看结果? int [][] arr=new int[3][2]; Sy ...
- Core Animation演示
相关代码展示: - (IBAction)toggleRoundCorners:(id)sender { [CATransaction setDisableActions:![_enableAnimat ...