HDU-1086-You can Solve a Geometry Problem too
来源:互联网 发布:java中webservice实例 编辑:程序博客网 时间:2024/05/16 08:28
#include<iostream>#include<string>#include<queue>#include<map>#include<set>#include<vector>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;/* 这个道算两条线段是否有交点,求交点个数;(不考虑交点重复的情况) 思路: 告诉你两条线段AB,CD;判断线段AB,CD是否相交只要判断直线AB与线段CD相交 以及直线CD与线段AB相交,那么便可以证明两线段相交; 判断直线与线段是否相交可以将线段的两个端点代入直线方程,若结果异号,说明直线与线段相交;*/typedef struct Point{ double x,y;}Point;// 判断直线AB是否与线段CD相交;bool Intersect(Point A,Point B,Point C,Point D){ // 直线方程F(x,y)为:(y-y1)*(x1-x2)-(x-x2)*(y1-y2)=0; double FC=(C.y-A.y)*(A.x-B.x)-(C.x-A.x)*(A.y-B.y); double FD=(D.y-A.y)*(A.x-B.x)-(D.x-A.x)*(A.y-B.y); if(FC*FD<=0) return true; else return false;}int main(){ int n; while(~scanf("%d",&n)){ if(!n) break; int sum=0; Point a[105],b[105]; for(int i=0;i<n;i++) scanf("%lf%lf%lf%lf",&a[i].x,&a[i].y,&b[i].x,&b[i].y); // 二重循环,遍历每条线段; for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ // 如果直线AB与线段CD相交且直线CD与线段AB相交,那么计数加一; if(Intersect(a[i],b[i],a[j],b[j])&&Intersect(a[j],b[j],a[i],b[i])) sum++; } } printf("%d\n",sum); } return 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
- HDU4634:Swipe Bo(BFS+状压)
- 小胖说事27-----IOS制作自已的静态framework
- ACM--Moving Tables
- 金朝阳——软件测试试题3道题目分享
- hdu 1203 I NEED A OFFER!
- HDU-1086-You can Solve a Geometry Problem too
- IOS开发点滴---UIView转UIImage以及切割UIView
- 公钥、私钥、SSL趣解
- Ubuntu通过源码编译安装Octave 4.0
- ubuntu14.04 64bit安装skype4.3
- hdu 1248 寒冰王座
- mongodb数据库的启动和停止
- Eclipse 如何同时打开查看多个文件
- hdu 1284 钱币兑换问题