题目大意:给出两条直线,每个直线上的两点,求这两条直线的位置关系:共线,平行,或相交,相交输出交点。

题目思路:主要在于求交点

F0(X)=a0x+b0y+c0==0;

F1(X)=a1x+b1y+c1==0;

设点(x0,y0)(x1,y1)过直线

解方程:a=y1-y0,b=x0-x1,c=x1y0-x0y1;

联立方程:

X=(b0c1-b1c0)/d;

Y=(a0c1-a1c0)/d;

d=a0b1-a1b0;

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<map>
#define INF 0x3f3f3f3f
#define MAX 100005
#define Temp 1000000000
#define MOD 1000000007 using namespace std; int n; int check(int x1,int y1,int x2,int y2,int x3,int y3)//叉积
{
return (x3-x2)*(y3-y1)-(x3-x1)*(y3-y2);
} void Point(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
int b0=x2-x1;
int b1=x4-x3;
int a0=y1-y2;
int a1=y3-y4;
int c0=x1*y2-x2*y1;
int c1=x3*y4-x4*y3;
int d=a0*b1-a1*b0;
double X=(b0*c1-b1*c0*1.0)/d;
double Y=(a1*c0-a0*c1*1.0)/d;
printf("POINT %.2f %.2f\n",X,Y);
} void solve(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
if(check(x1,y1,x2,y2,x3,y3)== && check(x1,y1,x2,y2,x4,y4)==)
printf("LINE\n");//共线
else if((y2-y1)*(x3-x4) == (y3-y4)*(x2-x1))
printf("NONE\n");//平行
else
Point(x1,y1,x2,y2,x3,y3,x4,y4);
} int main()
{
int n,x1,y1,x2,y2,x3,y3,x4,y4;
scanf("%d",&n);
printf("INTERSECTING LINES OUTPUT\n");
for(int i=; i<n; i++)
{
scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
solve(x1,y1,x2,y2,x3,y3,x4,y4);
}
printf("END OF OUTPUT\n");
return ;

Intersecting Lines POJ 1269的更多相关文章

  1. Intersecting Lines - POJ 1269(判断平面上两条直线的关系)

    分析:有三种关系,共线,平行,还有相交,共线和平行都可以使用叉积来进行判断(其实和斜率一样),相交需要解方程....在纸上比划比划就出来了....   代码如下: ================== ...

  2. 判断线段之间的关系(D - Intersecting Lines POJ - 1269 )

    题目链接:https://vjudge.net/contest/276358#problem/D 题目大意:每一次给你两条直线,然后问你这两条直线的关系(平行,共线,相交(输出交点)). 具体思路:先 ...

  3. POJ 1269 (直线求交)

    Problem Intersecting Lines (POJ 1269) 题目大意 给定两条直线,问两条直线是否重合,是否平行,或求出交点. 解题分析 主要用叉积做,可以避免斜率被0除的情况. 求交 ...

  4. 【POJ】1269 Intersecting Lines(计算几何基础)

    http://poj.org/problem?id=1269 我会说这种水题我手推公式+码代码用了1.5h? 还好新的一年里1A了---- #include <cstdio> #inclu ...

  5. poj 1269 Intersecting Lines

    题目链接:http://poj.org/problem?id=1269 题目大意:给出四个点的坐标x1,y1,x2,y2,x3,y3,x4,y4,前两个形成一条直线,后两个坐标形成一条直线.然后问你是 ...

  6. 判断两条直线的位置关系 POJ 1269 Intersecting Lines

    两条直线可能有三种关系:1.共线     2.平行(不包括共线)    3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...

  7. ●POJ 1269 Intersecting Lines

    题链: http://poj.org/problem?id=1269 题解: 计算几何,直线交点 模板题,试了一下直线的向量参数方程求交点的方法. (方法详见<算法竞赛入门经典——训练指南> ...

  8. POJ 1269 - Intersecting Lines - [平面几何模板题]

    题目链接:http://poj.org/problem?id=1269 Time Limit: 1000MS Memory Limit: 10000K Description We all know ...

  9. poj 1269 Intersecting Lines——叉积求直线交点坐标

    题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...

随机推荐

  1. javascript的insertBefore、insertAfter和appendChild简单介绍

      target.insertBefore(newChild,existingChild)参数说明:1.target:被添加节点和现有节点的父节点.2.newChild:将要被插入的节点.3.exis ...

  2. 导入excel表格的数据--->到mysql中

    01下载excel类,将Classes文件夹放入ThinkPHP\Extend\Vendor\位置 下载地址 http://phpexcel.codeplex.com/releases/view/26 ...

  3. webapi中的路由约束

    Route Constraints Route constraints let you restrict how the parameters in the route template are ma ...

  4. Codeforces Round #256 (Div. 2) B Suffix Structures

    Description Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" t ...

  5. 安装 sublime package control

    import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_p ...

  6. html5游戏开发框架之lufylegend开源库件学习记录

    下载地址http://lufylegend.com/lufylegend 引用 <script type="text/javascript" src="../luf ...

  7. 2.Perl 多线程:Threads(线程返回值)

    use warnings; use strict; use threads; sub TEST{ print "Hello, World!\n"; 'a'/); } #返回列表方法 ...

  8. 在textarea的内容后面增加内容

    document.getElementById("result").value+=data+"\n>"; 本文为本人用来记录自己做的一些东西,如有不对的地 ...

  9. [笔记]Practical Lessons from Predicting Clicks on Ads at Facebook

    ABSTRACT 这篇paper中作者结合GBDT和LR,取得了很好的效果,比单个模型的效果高出3%.随后作者研究了对整体预测系统产生影响的几个因素,发现Feature+Model的贡献程度最大,而其 ...

  10. 深入理解HTTP协议(转) 浏览器和服务器如何通信(HTTP协议)

    http协议学习系列 1. 基础概念篇 1.1 介绍 HTTP是Hyper Text Transfer Protocol(超文本传输协议)的缩写.它的发展是万维网协会(World Wide Web C ...