杭电hdu 1086 You can Solve a Geometry Problem too 线段相交
来源:互联网 发布:条码软件有哪些 编辑:程序博客网 时间:2024/05/18 06:25
http://acm.hdu.edu.cn/showproblem.php?pid=1086
判断两条线段是否相交。用叉乘来判断。
#include <stdio.h>struct Lpoint{double x;double y;};struct Llineseg{Lpoint a;Lpoint b;};//叉乘double xmulti(Lpoint p1, Lpoint p2, Lpoint p0){return ((p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y));}double mx(double a, double b){return a > b ? a : b;}double mn(double a, double b){return a < b ? a : b;}//判断相交int isinterls(Llineseg u, Llineseg v){return ((mx(u.a.x, u.b.x) >= mn(v.a.x, v.b.x)) &&(mx(v.a.x, v.b.x) >= mn(u.a.x, u.b.x)) &&(mx(u.a.y, u.b.y) >= mn(v.a.y, v.b.y)) &&(mx(v.a.y, v.b.y) >= mn(u.a.y, u.b.y)) &&(xmulti(v.a, u.b, u.a) * xmulti(u.b, v.b, u.a) >= 0) &&(xmulti(u.a, v.b, v.a) * xmulti(v.b, u.b, v.a) >= 0));}int main(){Llineseg line[101];int n, i, j, s;while(scanf("%d", &n)&&n){s = 0;scanf("%lf%lf%lf%lf", &line[0].a.x, &line[0].a.y, &line[0].b.x, &line[0].b.y);for(i = 1; i < n; i ++){scanf("%lf%lf%lf%lf", &line[i].a.x, &line[i].a.y, &line[i].b.x, &line[i].b.y);for(j = 0; j < i; j ++){if(isinterls(line[j], line[i]))s ++;}}printf("%d\n", s);}return 0;}
- 杭电hdu 1086 You can Solve a Geometry Problem too 线段相交
- 杭电 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[判断线段相交,完整版]
- 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 线段相交
- 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 5 News Stand应用程序之一 – 外观
- (二)利用Titanium Studio,快速开发移动应用(下载,安装Titanium Studio)
- Web服务小试——天气预报
- iPhone消息推送机制实现与探讨
- iOS开发之详解剪贴板
- 杭电hdu 1086 You can Solve a Geometry Problem too 线段相交
- 如何从众多开发者中华丽转身为管理者
- 析构函数的显示调用测试
- 分布式搜索elasticsearch java API 之(六)------批量添加删除索引
- HDU 1124 Factorial
- Linux编写新的系统调用(内核版本3.2.18)
- 字符编码笔记:ASCII,Unicode和UTF-8
- iOS开发之在地图上绘制出你运动的轨迹
- 自适应的网格布局-砌墙效果