poj 1269 Intersecting Lines
来源:互联网 发布:网络主播网站排行榜 编辑:程序博客网 时间:2024/05/29 06:30
题意:给个n,然后n行数据,每行四个点,代表两条直线,求两条直线平行,或者重合,或者相交,相交的话求出交点
叉积求交点公式:黑书p357
#include <cstdio>#include <cstring>struct Point{ int x,y;};struct Line{ Point s,e;};Line line1,line2;int det(int x1, int y1, int x2, int y2){ return x1*y2 - x2*y1;}/****求ab和ac叉积****/int cross(Point a, Point b, Point c){ return det(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);}int area(Point a, Point b, Point c){ return cross(a,b,c);}int main(){ int n; while(scanf("%d",&n) != EOF) { printf("INTERSECTING LINES OUTPUT\n"); for(int i = 0; i < n; ++i) { scanf("%d %d %d %d %d %d %d %d",&line1.s.x,&line1.s.y,&line1.e.x,&line1.e.y,&line2.s.x,&line2.s.y,&line2.e.x,&line2.e.y);// line1.e.x-line1.s.x,line1.e.y-line1.s.y------>x1,y1// line2.e.x-line2.s.x,line2.e.y-line2.s.y------>x2,y2 if((line1.e.x-line1.s.x)*(line2.e.y-line2.s.y) - (line1.e.y-line1.s.y)*(line2.e.x-line2.s.x) == 0)//共线,然后判断平行还是重合 { if(cross(line1.s,line1.e,line2.s) == 0) printf("LINE\n"); else printf("NONE\n"); } //肯定就有交点了 else { float s1 = area(line1.s,line1.e,line2.s)/2.0; float s2 = area(line1.s,line1.e,line2.e)/2.0; printf("POINT %.2f %.2f\n",(s1*line2.e.x-s2*line2.s.x)/(s1-s2),(s1*line2.e.y-s2*line2.s.y)/(s1-s2)); } } printf("END OF OUTPUT\n"); } return 0;}
0 0
- POJ 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- poj 1269 Intersecting Lines
- POJ 1269 Intersecting Lines
- 浅谈JavaScript的事件对象event
- Codevs 2066 三角恋
- 网络爬虫(二)——《金刚:骷髅岛》电影分析
- js 实现链表
- 【adb】cmd命令行输入adb时始终提示adb为非内部命令
- poj 1269 Intersecting Lines
- 设计模式-原型模式
- Git 仓库常用操作
- HDMI EDID
- OJ 2990 Problem E 链表的基本运算(线性表)
- Java web 服务器集群 session共享解决思路
- 遍历文件夹
- Linux 内核时钟架构之时钟事件设备SYS接口
- UVALive