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. C++中虚函数功能的实现机制

    要理解C++中虚函数是如何工作的,需要回答四个问题. 1.  什么是虚函数. 虚函数由于必须是在类中声明的函数,因此又称为虚方法.所有以virtual修饰符开始的成员函数都成为虚方法.此时注意是vir ...

  2. apache rewrite rule

    http://10.58.104.19:8008/site/833/3f11d2b44b7d3baa2149f26a30f8c68d/b.js?siteid=332323 将一个静态请求转换成一个动态 ...

  3. Linux命令之切换用户

    一.从 user 用户切换到 root 用户 不管是用图形模式登录 Ubuntu,还是命令行模式登录,我们会发现缺省的用户是 user,但是当我们需要执行一些具有 root 权限的操作(如修还系统文件 ...

  4. Java中单例七种写法(懒汉、恶汉、静态内部类、双重检验锁、枚举)

    /*** * 懒汉模式 1 * 可以延迟加载,但线程不安全. * @author admin * */ public class TestSinleton1 { private static Test ...

  5. Jquery 获取IP地址

    //获取ip和地址 $(function () { var url = 'http://chaxun.1616.net/s.php?type=ip&output=json&callba ...

  6. Android 利用摄像头指尖测试心率

    过摄像头来获得心率,搜了一下这个技术真不是噱头,据说在iPhone早有实现,主要原理是:当打开软件时,手机的闪光灯也会被自动打开,用户将手指放在摄像头上时,指尖皮下血管由于有血液被压入,被光源照射的手 ...

  7. FileInputStream(字节流)与fileReader(字符流) 的区别

    FileInputStream 类 1 ) FileInputStream 类介绍: 以字节为单位的流处理.字节序列:二进制数据.与编码无关,不存在乱码问题. FileInputStream 类的主要 ...

  8. Naive Bayes Theorem and Application - Theorem

    Naive Bayes Theorm And Application - Theorem Naive Bayes model: 1. Naive Bayes model 2. model: discr ...

  9. android 关于多任务下载问题

    关于多任务下载问题    近期项目中,遇到一个问题,列表数据中的图片地址是一个需要下载JS再解析的字段,之前的图片下载是一个异步的过程,由一个队列处理. Android系统以不同寻常的方式处理多个应用 ...

  10. 一步一步学数据结构之1--n(通用树)

    今天来看大家介绍树,树是一种非线性的数据结构,树是由n个结点组成的有限集合,如果n=0,称为空树:如果n>0,则:有一个特定的称之为根的结点,它只有直接后继,但没有直接前驱:除根以外的其他结点划 ...