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 ...
随机推荐
- Clamp函数
Clamp函数可以将随机变化的数值限制在一个给定的区间[min, max]内: template<class T> T Clamp(T x, T min, T max) { if (x & ...
- 快速的CDN加速服务
jQuery Migrate jQuery官网CDN地址jQuery版本迁移辅助插件,用jquery不同版本开发的程序在修改jquery版本出现的兼容问题可以使用jQuery Migrate解决此问题 ...
- UVA 11475 Extend to Palindrome(后缀数组+ST表)
[题目链接] http://acm.hust.edu.cn/vjudge/problem/27647 [题目大意] 给出一个字符串,要求在其后面添加最少的字符数,使得其成为一个回文串.并输出这个回文串 ...
- nmon related
nmon related pGraph (supports nmon) https://www.ibm.com/developerworks/community/wikis/home?lang=en# ...
- tp中phpexcel导出实例
public function phpexcel(){ //测试$this->display("User:xx");//跨模块分配页面User模块xx.html // xx\ ...
- cocos android分析
来自:http://xiebaochun.github.io/ cocos2d-x Android环境搭建 cocos2d-x环境搭建比較简单,可是小问题还是不少,我尽量都涵盖的全面一些. 下载软件 ...
- 超高性价比USB转CAN适配器,2500V工业级隔离,兼容ZLG软件
淘宝链接: http://item.taobao.com/item.htm?spm=a230r.1.14.16.QGsAZg&id=20134109594&initiative_new ...
- Swift和Objective-C混合编程
假设你现在就是一个iOS程序员,你对Objective-C很熟悉,对iOS开发也很熟悉,然而,苹果公司在iOS 8之后推出了Swift语言.那么,如何才能快速地从Objective-C过渡到Swift ...
- C++学习笔记29,引用变量(1)
引用变量在创建的时候就必须初始化.无法创建一个未被初始化的引用. #include <iostream> using namespace std; int main() { int x=1 ...
- HTML5API___Web Storage
Web Storage 是html5的本地存储规范 支持:移动平台基本支持 (opera mini除外) ie8+ff chrome 等 支持 它包含2个: sessionStorage 会话存储 ...