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

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

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. POJ 3268 Silver Cow Party(dij+邻接矩阵)

    ( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<algorithm> #include<cs ...

  2. Kettle中spoon.sh在使用时报错

    报错信息: Attempting to load ESAPI.properties via file I/O. Attempting to load ESAPI.properties as resou ...

  3. Linux添加软件连接方法

    这是linux中一个非常重要命令,请大家一定要熟悉.它的功能是为某一个文件或目录在另外一个位置建立一个同步的链接,类似Windows下的超级链接. 这个命令最常用的参数是-s,具体用法是:sudo l ...

  4. yum安装memcache,mongo扩展以及python的mysql模块安装

    //启动memcached/usr/local/memcached/bin/memcached -d -c 10240 -m 1024 -p 11211 -u root/usr/local/memca ...

  5. 使 httpClient 支持中文

    一个有效的方法:重载 PostMethod 的 getRequestCharSet 方法 1: class PostChinese { 2: HttpClient httpClient = new H ...

  6. poj2140(奇因数的个数)

    #include<stdio.h>int main(){ int n,s=0; scanf("%d",&n); for(int i=1;i<=n;i++) ...

  7. G - Zombie’s Treasure Chest(动态规划专项)

    G - Zombie’s Treasure Chest Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

  8. thinkPHP框架学习笔记

    class ZhuantiAction extends Action { public function index() { $name = trim($this->_get('name')); ...

  9. js常用API 数据类型 基本类型,基本包装类型,引用类型 Object String Array Boolean Number Date Math

    数据类型 变量.作用域及内存 基础类型(primitive value):Undefined.Null.Boolean.Number和String.这些类型在内存中分别占用固定大小的空间,他们的值保存 ...

  10. Webdriver如何解决页面元素过期:org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up

    当运行Webdriver时抛出如下异常:org.openqa.selenium.StaleElementReferenceException: Element not found in the cac ...