Intersecting Lines
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 12844   Accepted: 5703

Description

We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one another (i.e. they are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect.
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

The
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

There
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
题解:用%lfwa了半天,好无奈改成%f就过了。。。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define geta(y1,y2)(y1-y2)
#define getb(x1,x2)(x2-x1)
#define getc(x1,x2,y1,y2)(x2*y1-x1*y2)
//int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
int js(double &x,double &y){
int x1,x2,x3,x4,y1,y2,y3,y4;
scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
int a1,a2,b1,b2,c1,c2;
a1=geta(y1,y2);b1=getb(x1,x2);c1=-getc(x1,y1,x2,y2);
a2=geta(y3,y4);b2=getb(x3,x4);c2=-getc(x3,y3,x4,y4);
//int t1=gcd(a1,gcd(b1,c1)),t2=gcd(a2,gcd(b2,c2));
// a1/=t1;b1/=t1;c1/=t1;a2/=t2;b2/=t2;c2/=t2;
if(a1*b2==b1*a2){
if(a1*c2==a2*c1&&b1*c2==b2*c1)return ;
else return ;
} y=-1.0*(a2*c1-a1*c2)/(a2*b1-a1*b2);
x=1.0*(b2*c1-b1*c2)/(a2*b1-a1*b2);
return ;
}
void input(int T,int cnt){
while(T--){
double x,y;
int temp=js(x,y);
if(temp==)puts("LINE");
else if(temp==)puts("NONE");
else printf("POINT %.2lf %.2lf\n",x,y);}
}
int main(){
int T;
// while(~scanf("%d",&T)){
scanf("%d",&T);
puts("INTERSECTING LINES OUTPUT");
input(T,);
puts("END OF OUTPUT");
// }
return ;}
												

Intersecting Lines(数学)的更多相关文章

  1. POJ 1269 Intersecting Lines --计算几何

    题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...

  2. POJ 1269 Intersecting Lines【判断直线相交】

    题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...

  3. 简单几何(直线位置) POJ 1269 Intersecting Lines

    题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...

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

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

  5. POJ 1269 Intersecting Lines(计算几何)

    题意:给定4个点的坐标,前2个点是一条线,后2个点是另一条线,求这两条线的关系,如果相交,就输出交点. 题解:先判断是否共线,我用的是叉积的性质,用了2遍就可以判断4个点是否共线了,在用斜率判断是否平 ...

  6. poj 1269 Intersecting Lines

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

  7. POJ 1269 Intersecting Lines(直线相交判断,求交点)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8342   Accepted: 378 ...

  8. POJ 1269 Intersecting Lines(几何)

    题目链接 题意 : 给你两条线段的起点和终点,一共四个点,让你求交点坐标,如果这四个点是共线的,输出“LINE”,如果是平行的就输出“NONE”. 思路 : 照着ZN留下的模板果然好用,直接套上模板了 ...

  9. POJ 1269 (直线相交) Intersecting Lines

    水题,以前总结的模板还是很好用的. #include <cstdio> #include <cmath> using namespace std; ; int dcmp(dou ...

随机推荐

  1. TOJ 1139.Compromise

    2015-06-03 问题简述: 大概就是输入两段文本(用小写英文字母表示),分别用#表示一段话的结束输入,输出这两个文本的最长公共子序列. 简单的LCS问题,但是输入的是一段话了,而且公共部分比较是 ...

  2. linux杂记(四)热键[Tab],[ctrl]-c,[ctrl]-d,在线求助man page/info page

    [Tab]按键 他具有[命令补全](接在一串指令的第一个字后面)与[档案补齐](接在第一串指令的第二字以后时)的功能.如 [KANO@kelvin ~]$ ca[tab][tab] cabextrac ...

  3. Howie带你云上飘-新浪云

    介绍一下怎么在sae上做个网站 前言 曾经,sae是收费的,计时收费,还挺贵的呢.所以就试玩了一下,没敢继续鼓捣.后来,云计算越来越火了,新浪也不差钱嘛,于是直接给新注册的开发者送好多豆子,于是,免费 ...

  4. Minix

    [1]  MINIX是一种基于微内核架构的类UNIX计算机操作系统,由Andrew S. Tanenbaum发明.MINIX最初发布于1987年,开放全部源代码给大学教学和研究工作.2000年重新改为 ...

  5. 繁简转换OpenCC,autogb 和 autob5,iconv,python的jianfan包

    OpenCC OpenCC 是跨平台.多语言的开放中文转换库,除了基本的简繁转换功能外,用户还可以选择对不同用词习惯和异体字的处理方式. OpenCC 还提供方便的网页转换界面. OpenOffice ...

  6. ios app唤起页面跳转

    有些时候我们需要再其他地方把app唤起,并打开跳转到指定的vc上面.这里我自己写了一个vc的mgr,最主要的技术是method swizzle.原理就不详述,看代码吧. // // ViewContr ...

  7. 30天自制操作系统第八天学习笔记(u盘软盘双启动版本)

    暑假学习小日本的那本书:30天自制操作系统 qq交流群:122358078    ,更多学习中的问题.资料,群里分享 environment:开发环境:ubuntu 第八天的学习思考: 关于鼠标是怎么 ...

  8. Objective-C中math.h数学计算公式介绍

    1. 三角函数  double sin (double); 正弦  double cos (double);余弦  double tan (double);正切 2 .反三角函数   double a ...

  9. POJ 3169 Layout (图论-差分约束)

    Layout Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6574   Accepted: 3177 Descriptio ...

  10. objective-c 中随机数的用法 (3种:arc4random() 、random()、CCRANDOM_0_1() )

    1.随机数的使用      1).arc4random() 比较精确不需要生成随即种子 使用方法 : 通过arc4random() 获取0到x-1之间的整数的代码如下: int value = arc ...