hdoj1086 You can Solve a Geometry Problem too(数学几何题)
来源:互联网 发布:linux列出所有用户 编辑:程序博客网 时间:2024/04/29 02:27
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1086
有两种思路
1.求出某一直线的方程式,将另一线段两端点代入判断正负。
2.叉乘的思想
这里用的是叉乘的方法(写这个得细心些)
代码如下
#include<stdio.h>#include<string>#include<math.h> #include<iostream>using namespace std;#define Max 0x7ffffffdouble Max1(double a,double b){ a=(a>b)?a:b; return a ;}double Min1(double a,double b){ a=(a<b)?a:b; return a ;}struct point{double x,y;};struct line{point a,b;};double xmulti(point a1,point a2,point a3){return (a1.x-a3.x)*(a2.y-a3.y)-(a1.y-a3.y)*(a2.x-a3.x);}int judge(line l1,line l2){if(Max1(l1.a.x,l1.b.x)>=Min1(l2.a.x,l2.b.x)&&Max1(l1.a.y,l1.b.y)>=Min1(l2.a.y,l2.b.y)&&Max1(l2.a.x,l2.b.x)>=Min1(l1.a.x,l1.b.x)&&Max1(l2.a.y,l2.b.y)>=Min1(l1.a.y,l1.b.y)&&xmulti(l1.a,l2.b,l2.a)*xmulti(l1.b,l2.b,l2.a)<=0&&xmulti(l2.a,l1.b,l1.a)*xmulti(l2.b,l1.b,l1.a)<=0)return 1;return 0;}int main(){int n,i,j,cnt; line l[101];while(~scanf("%d",&n)&&n){for(i=0;i<n;i++){scanf("%lf%lf%lf%lf",&l[i].a.x,&l[i].a.y,&l[i].b.x,&l[i].b.y);}cnt=0;for(i=0;i<n;i++)for(j=i+1;j<n;j++){if(judge(l[i],l[j]))cnt++;}printf("%d\n",cnt);}return 0;}
阅读全文
0 0
- hdoj1086 You can Solve a Geometry Problem too(数学几何题)
- HDU1086 You can Solve a Geometry Problem too(数学几何)
- hdu_1086 You can Solve a Geometry Problem too(计算几何)
- You can Solve a Geometry Problem too
- You can Solve a Geometry Problem too
- You can Solve a Geometry Problem too
- 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 && 简单几何
- ACM-计算几何之You can Solve a Geometry Problem too——hdu1086
- hdu 1086 You can Solve a Geometry Problem too(几何(线段相交))
- You can Solve a Geometry Problem too(计算几何_求线段相交)
- hdoj 1086 You can Solve a Geometry Problem too 【计算几何】
- hdu1086+You can Solve a Geometry Problem too(计算几何,计算线段交点个数)
- HDUOJ-1086 You can Solve a Geometry Problem too(简单几何)
- You can Solve a Geometry Problem too (hdu1086)几何,判断两线段相交
- HDU 1086 You can Solve a Geometry Problem too(计算几何)
- HDU 1086 You can Solve a Geometry Problem too [计算几何]
- mybatis 动态sql和参数
- 旋转数字的最小数字
- 【社会我毅哥,人好话不多】
- 洛谷Oj-最大子段和-动态规划
- クラウドアプリのベスト設計とは? タイプが異なる「PaaS」組み合わせ事例
- hdoj1086 You can Solve a Geometry Problem too(数学几何题)
- QT中的信号和槽机制
- 文本和字体
- 缤特力m165连接ThinkPad-X250
- 【机器学习】特征工程概述
- 软件开发为什么很难
- hbase-创建连接报错 java.lang.OutOfMemoryError: unable to create new native thread
- 爱的时候,好好爱(转)
- 知识点总结