hdu 1086 You can Solve a Geometry Problem too(线段相交的交点个数)
来源:互联网 发布:java工厂模式的作用 编辑:程序博客网 时间:2024/06/05 10:31
和上一题差不多,只是变成了计数。
可是我改了上题的那个flag部分和数组大小去交却是wa。
然后我把读入改成了直接读到对应线段的对应点的对应坐标,以及判断线段相交的函数改成
传两条线段的四个端点就AC了。。。不知道为嘛。。。。
#include<cstdio>#include<iostream>#include<cstring>#define maxn 110using namespace std;struct Point{ double x,y;}point[maxn<<1];struct node{ Point a,b;}seg[maxn];typedef long long ll;double direction(Point a,Point b,Point c){ double c1,c2,c3,c4; c1 = c.x-a.x; c2 = c.y-a.y; c3 = b.x-a.x; c4 = b.y-a.y; return (c1*c4-c2*c3);}bool onsegment(Point a,Point b,Point c){ if(c.x<=max(a.x,b.x) && c.x>=min(a.x,b.x) && c.y<=max(a.y,b.y)&& c.y>=min(a.y,b.y)) return true; else return false;}bool segintersect(Point a,Point b,Point c,Point d){ double d1,d2,d3,d4; d1 = direction(a,b,c); d2 = direction(a,b,d); d3 = direction(c,d,a); d4 = direction(c,d,b); if(d1*d2<0 && d3*d4<0) return true; else if(d1==0 && onsegment(a,b,c)) return true; else if(d2==0 && onsegment(a,b,d)) return true; else if(d3==0 && onsegment(c,d,a)) return true; else if(d4==0 && onsegment(c,d,b)) return true; else return false;}int main(){ int n; while(scanf("%d",&n)!=EOF) { if(n==0) break; for(int i=0;i<n;i++) scanf("%lf%lf%lf%lf",&seg[i].a.x,&seg[i].a.y,&seg[i].b.x,&seg[i].b.y); int ans = 0; for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(segintersect(seg[i].a,seg[i].b,seg[j].a,seg[j].b)) ans++; } } printf("%d\n",ans); } return 0;}
0 0
- hdu 1086 You can Solve a Geometry Problem too(线段相交的交点个数)
- [ACM] hdu 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(简单的线段相交)
- 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(线段相交判定)
- ccx ndk release
- 从零开始—随机种子的应用
- junit 测试中各种断言用法
- poj 1651 Multiplication Puzzle dp
- unix网络编程卷1 时间获取客户端程序
- hdu 1086 You can Solve a Geometry Problem too(线段相交的交点个数)
- HDU-2032-直角杨辉三角
- spring自定义FactoryBean
- HDU-#2544 最短路(Dijkstra、Floyd、Bellman-Ford、SPFA)
- UI----UIslider 和UIcontrol的属性
- 计算机体系结构的铁律(iron law)
- 比较两表数据
- 关于异或加密算法的小游戏
- 黑马程序员-面向对象总结(1)