ACM/ICPC 之 平面几何-两直线关系(POJ 1269)
题意:给定四点的坐标(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)的更多相关文章
- ACM/ICPC 之 欧拉回路两道(POJ1300-POJ1386)
两道有关欧拉回路的例题 POJ1300-Door Man //判定是否存在从某点到0点的欧拉回路 //Time:0Ms Memory:116K #include<iostream> #in ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- POJ 1269 Intersecting Lines(判断两直线位置关系)
题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...
- 【转】lonekight@xmu·ACM/ICPC 回忆录
转自:http://hi.baidu.com/ordeder/item/2a342a7fe7cb9e336dc37c89 2009年09月06日 星期日 21:55 初识ACM最早听说ACM/ICPC ...
- 【转】ACM/ICPC生涯总结暨退役宣言—alpc55
转自:http://hi.baidu.com/accplaystation/item/ca4c2ec565fa0b7fced4f811 ACM/ICPC生涯总结暨退役宣言—alpc55 前言 早就该写 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- spring InitializingBean接口
最近工作需要得到sping中的每个事物需要执行的sql,称机会简单研究了一下spring的事务,项目中管理事务比较简单,用TransactionTemplate,就直接以TransactionTemp ...
- php函数mt_rand和rand 速度测试
今天在写代码时,看到以前的同时写了一个取随机数,用到了mt_rand(2,19) 就顺手搜了一下,mt_rand和rand的区别. 先看官方的解释 mt_rand 和 rand mt_rand — 生 ...
- C语言内存管理(转)
伟大的Bill Gates 曾经失言: 640K ought to be enough for everybody — Bill Gates 1981 程序员们经常编写内存管理程序,往往提心吊胆.如果 ...
- 【干货理解】理解javascript中实现MVC的原理
理解javascript中的MVC MVC模式是软件工程中一种软件架构模式,一般把软件模式分为三部分,模型(Model)+视图(View)+控制器(Controller); 模型:模型用于封装与应用程 ...
- Supervisor 安装与配置
Supervisor是一个进程监控程序. 满足的需求是:我现在有一个进程需要每时每刻不断的跑,但是这个进程又有可能由于各种原因有可能中断.当进程中断的时候我希望能自动重新启动它,此时,我就需要使用到了 ...
- AngularJS 使用ngOption实现下拉列表
最近使用到了ngOption实现下拉选择列表,由于需要实现分组等功能,百度了下没有太好的文章,就百度到一篇英文的帖子,按照其中的代码很顺利的搞定了. 本篇根据文中代码,详细讲述下如何实现下拉列表 更多 ...
- Nginx 502 bad gateway问题的解决方法
Nginx 502 Bad Gateway的含义是请求的PHP-CGI已经执行,但是由于某种原因(一般是读取资源的问题)没有执行完毕而导致PHP-CGI进程终止,一般来说Nginx 502 Bad G ...
- 必须知道的.net——学习笔记1
1.对象的生成(出生) Person aperson=new Person("小张",25) 构造过程:分配存储空间—初始化附加成员—调用构造函数 2.对象的旅程(在一定的约定与规 ...
- Codeforces Round #302 (Div. 2).C. Writing Code (dp)
C. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard inp ...
- hash-2.hashMap
1.HashMap的数据结构 a.HashMap是一个链表散列的结合体,即,数组和链表的结合体. b.HashMap类中定义了Entry类型的数组,Entry [ ] ,Entry有key value ...