Intersecting Lines(数学)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 12844 | Accepted: 5703 |
Description
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
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
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(数学)的更多相关文章
- POJ 1269 Intersecting Lines --计算几何
题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...
- POJ 1269 Intersecting Lines【判断直线相交】
题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...
- 简单几何(直线位置) POJ 1269 Intersecting Lines
题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...
- 【POJ】1269 Intersecting Lines(计算几何基础)
http://poj.org/problem?id=1269 我会说这种水题我手推公式+码代码用了1.5h? 还好新的一年里1A了---- #include <cstdio> #inclu ...
- POJ 1269 Intersecting Lines(计算几何)
题意:给定4个点的坐标,前2个点是一条线,后2个点是另一条线,求这两条线的关系,如果相交,就输出交点. 题解:先判断是否共线,我用的是叉积的性质,用了2遍就可以判断4个点是否共线了,在用斜率判断是否平 ...
- poj 1269 Intersecting Lines
题目链接:http://poj.org/problem?id=1269 题目大意:给出四个点的坐标x1,y1,x2,y2,x3,y3,x4,y4,前两个形成一条直线,后两个坐标形成一条直线.然后问你是 ...
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8342 Accepted: 378 ...
- POJ 1269 Intersecting Lines(几何)
题目链接 题意 : 给你两条线段的起点和终点,一共四个点,让你求交点坐标,如果这四个点是共线的,输出“LINE”,如果是平行的就输出“NONE”. 思路 : 照着ZN留下的模板果然好用,直接套上模板了 ...
- POJ 1269 (直线相交) Intersecting Lines
水题,以前总结的模板还是很好用的. #include <cstdio> #include <cmath> using namespace std; ; int dcmp(dou ...
随机推荐
- Spark源码学习1
转自:http://www.cnblogs.com/hseagle/p/3664933.html 一.基本概念(Basic Concepts) RDD - resillient distributed ...
- WCF 接收、发送数据的大小及时间的设置
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="/> & ...
- 网络抓包--Wireshark
Wireshark 是一款非常棒的Unix和Windows上的开源网络协议分析器.它可以实时检测网络通讯数据,也可以检测其抓取的网络通讯数据快照文件.可以通过图形界面浏览这些数据,可以查看网络通讯数据 ...
- Umbraco学习2------数据类型
一.基础概念 在使用Umbraco这类CMS制作网站之前,先要搞清楚的是,和概念中网站制作的区别. 暂时忘掉所谓的ADO.NET存储.忘掉ASP.NET.忘掉多层架构什么的. 只需要关注:要显示什么. ...
- Maven项目 Spring 单元测试
使用maven创建web工程,将Spring配置文件applicationContext.xml放在src/resource下,用eclipse编译时提示class path resource [ap ...
- cocos2d-x过程动作CCProgressTo示例学习笔记
// // SpriteProgressToRadial // //------------------------------------------------------------------ ...
- Android实现左右滑动指引效果
本文介绍Android中实现左右滑动的指引效果. 关于左右滑动效果,我在以前的一篇博文中提到过,有兴趣的朋友可以查看:http://www.cnblogs.com/hanyonglu/archive/ ...
- Cocos2d-iPhone V3 (2) 场景转换
Cocos2d-iPhone V3 (2) 场景转换 博客:http://blog.csdn.net/prevention 作者:大锐哥 - 1. 准备工作 创建一个场景会吧? #import &qu ...
- Selenium之偷懒教程
进来一直停留在基础理论知识的学习中,认为太乏味,就写了一个网页自己主动化的demo:自己主动写日报.省的以后自己打开网页写啦. 直接上代码: 自己主动填写日报DEMO import java.io.B ...
- 七日筑基——C#第一天(下)
继续C#第一天的内容,昨天我们简单说了一下如何用C#代码来让学生做自我介绍,介绍的格式要求:“我叫威震天,今年20岁,我喜欢踢足球和上网,希望接下来的三年能跟大家一起成长.”威震天介绍完了,继续下一个 ...