题意:给定四点的坐标(x,y),分别确定两直线,求出其交点,若重合or平行则输出相应信息

  • 用四个点的坐标算出直线通式(ax+by+c=0)中的a,b,c,然后利用a,b,c计算出交点坐标(其他公式不够通用= =,比如斜率限制)
  • 我利用两次平行判定重合
  • 公式利用 初高中数学知识代数知识 在草纸上仔细推导出来= =,让a,b,c为整数,比如可以演算得到a = y2-y1,b = x1-x2这一类公式。

  详细Code如下

 //给定四点,分别确定两直线,求出其交点,若重合or平行则输出相应信息
//Memory 206 K,Time: 0 Ms
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; struct Point{
int x,y;
}; struct Line{
int a,b,c;
}; /*Judge s1-s2和s3-s4两条线平行*/
int parallel(Point s1,Point s2,Point s3,Point s4)
{
if((s1.y-s2.y)*(s3.x-s4.x) == (s1.x-s2.x)*(s3.y-s4.y))
return ;
else
return ;
} /*构造直线*/
Line lineform(int x1,int y1,int x2,int y2)
{
Line temp;
temp.a = y2 - y1;
temp.b = x1 - x2;
temp.c = -(temp.a*x1+temp.b*y1);
return temp;
} int main()
{
int T;
Point p[];
Line l1,l2;
int i; cin>>T;
cout<<"INTERSECTING LINES OUTPUT"<<endl;
while(T--)
{
for(i=;i<;i++)
scanf("%d%d",&p[i].x,&p[i].y); if(parallel(p[],p[],p[],p[])) //平行
{
if(parallel(p[],p[],p[],p[])) //重合
cout<<"LINE"<<endl;
else
cout<<"NONE"<<endl;
}
else
{
l1 = lineform(p[].x,p[].y,p[].x,p[].y);
l2 = lineform(p[].x,p[].y,p[].x,p[].y); /* 求交点 */
double x,y,d;
d = l2.a*l1.b-l1.a*l2.b;
x = -(l1.b*l2.c - l2.b*l1.c)/d;
y = (l1.a*l2.c - l2.a*l1.c)/d;
printf("POINT %.2lf %.2lf\n",x,y);
}
}
cout<<"END OF OUTPUT"<<endl; return ;
}

ACM/ICPC 之 平面几何-两直线关系(POJ 1269)的更多相关文章

  1. ACM/ICPC 之 欧拉回路两道(POJ1300-POJ1386)

    两道有关欧拉回路的例题 POJ1300-Door Man //判定是否存在从某点到0点的欧拉回路 //Time:0Ms Memory:116K #include<iostream> #in ...

  2. 判断两条直线的位置关系 POJ 1269 Intersecting Lines

    两条直线可能有三种关系:1.共线     2.平行(不包括共线)    3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...

  3. POJ 1269 Intersecting Lines(判断两直线位置关系)

    题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...

  4. 【转】lonekight@xmu·ACM/ICPC 回忆录

    转自:http://hi.baidu.com/ordeder/item/2a342a7fe7cb9e336dc37c89 2009年09月06日 星期日 21:55 初识ACM最早听说ACM/ICPC ...

  5. 【转】ACM/ICPC生涯总结暨退役宣言—alpc55

    转自:http://hi.baidu.com/accplaystation/item/ca4c2ec565fa0b7fced4f811 ACM/ICPC生涯总结暨退役宣言—alpc55 前言 早就该写 ...

  6. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering

    Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...

  7. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time

    Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...

  8. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

  9. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

随机推荐

  1. Java8初体验(二)Stream语法详解

    感谢同事[天锦]的投稿.投稿请联系 tengfei@ifeve.com 上篇文章Java8初体验(一)lambda表达式语法比 较详细的介绍了lambda表达式的方方面面,细心的读者会发现那篇文章的例 ...

  2. 【转】apache kafka监控系列-KafkaOffsetMonitor

    apache kafka监控系列-KafkaOffsetMonitor 时间 2014-05-27 18:15:01  CSDN博客 原文  http://blog.csdn.net/lizhitao ...

  3. css3 实现逐帧动画

    css3 实现逐帧动画 实现逐帧动画需要使用到的是Animation动画,该CSS3的Animation有八个属性:分别是如下:1: animation-name2: animation-durati ...

  4. PHP中的位运算与位移运算(其它语言通用)

    /* PHP中的位运算与位移运算 ======================= 二进制Binary:0,1 逢二进1,易于电子信号的传输 原码.反码.补码 二进制最高位是符号位:0为正数,1为负数( ...

  5. Maven 跳过测试目录

    在命令行使用 mvn install -Dmaven.skipTests 或 mvn install -Dmaven.test.skip=true 或在pom.xml设置 <build> ...

  6. 如何用SQL命令行工具删除dedecms指定id文章

    用dedecms采集时标题字段设置错了,出现了注释符号<!---->,导致后台的文章列表出现错误,也无法直接从列表中删除,可以远程登录数据库去操作,这个相对比较麻烦,想着直接从后台的SQL ...

  7. Bootstrap编码规范

    黄金定律 永远遵循同一套编码规范 -- 可以是这里列出的,也可以是你自己总结的.如果你发现本规范中有任何错误,敬请指正.通过 open an issue on GitHub为本规范添加或贡献内容. 不 ...

  8. php数据结构与算法

    php面试题之二--数据结构和算法(高级部分) 二.数据结构和算法 1.使对象可以像数组一样进行foreach循环,要求属性必须是私有.(Iterator模式的PHP5实现,写一类实现Iterator ...

  9. javaweb 解决将ajax返回的内容用document.write写入,FireFox一直加载的问题

    在document.write方法后加上document.close就解决了, 想知道原理的小伙伴可以继续看 浏览器在解析html时会打开一个流,这是用document.write中写入,是加入当解析 ...

  10. 访问者(Visitor)模式

    http://www.cnblogs.com/zhenyulu/articles/79719.html 一. 访问者(Visitor)模式 访问者模式的目的是封装一些施加于某种数据结构元素之上的操作. ...