HDU-1086 You can Solve a Geometry Problem too
来源:互联网 发布:《算法》和算法导论 编辑:程序博客网 时间:2024/06/05 02:10
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <algorithm>using namespace std;struct jd{ double x1,y1,x2,y2;};int main(){ int n,i,cnt,k,q; double a,b,mi1,ma1,mi2,ma2; struct jd p[105]; while (scanf("%d",&n),n!=0) { k=0;cnt=0; scanf("%lf%lf%lf%lf",&p[k].x1,&p[k].y1,&p[k].x2,&p[k].y2); k++; while (k<n) { q=0; scanf("%lf%lf%lf%lf",&p[k].x1,&p[k].y1,&p[k].x2,&p[k].y2); for (i=0;i<k;i++) { a=((p[k].x1-p[i].x1)*(p[i].y2-p[i].y1)-(p[k].y1-p[i].y1)*(p[i].x2-p[i].x1))* ((p[i].x2-p[i].x1)*(p[k].y2-p[i].y1)-(p[i].y2-p[i].y1)*(p[k].x2-p[i].x1)); b=((p[i].x1-p[k].x1)*(p[k].y2-p[k].y1)-(p[i].y1-p[k].y1)*(p[k].x2-p[k].x1))* ((p[k].x2-p[k].x1)*(p[i].y2-p[k].y1)-(p[k].y2-p[k].y1)*(p[i].x2-p[k].x1)); if (a>=0&&b>=0) cnt++; } k++; } printf("%d\n",cnt); } return 0;}
判断两线段是否相交,可以把两条线段换成向量,如果线段P1P2和直线Q1Q2相交,则P1P2跨立Q1Q2,即:( P1 - Q1 ) × ( Q2 - Q1 ) * ( Q2 - Q1 ) × ( P2 - Q1 ) >= 0,
如果线段Q1Q2和直线P1P2相交,则Q1Q2跨立P1P2,即:( Q1 - P1 ) × ( P2 - P1 ) * ( P2 - P1 ) × ( Q2 - P1 ) >= 0。
0 0
- hdu 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- hdu/hdoj 1086 You can Solve a Geometry Problem too
- hdu-1086You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- HDU 1086:You can Solve a Geometry Problem too
- HDU 1086You can Solve a Geometry Problem too
- hdu 1086 You can Solve a Geometry Problem too
- HDU-1086-You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- HDU-1086 You can Solve a Geometry Problem too
- HDU-1086-You can Solve a Geometry Problem too
- HDU 1086 You can Solve a Geometry Problem too
- 深度学习中梯度下降知识准备
- iOS中消息转发的实现
- Heritrix1.14源码分析(1) 包介绍
- 内部类
- gdb调试
- HDU-1086 You can Solve a Geometry Problem too
- malloc和 calloc的区别
- 01:台风
- 卡特兰数
- 「HD_ACM」The Seven Percent Solution
- 如何把事情做到最好读书笔记5
- Heritrix1.14源码分析(2) 配置文件order.xml介绍
- Linux netstat命令详解(转)
- 如何把事情做到最好读书笔记6