hdu 1086 You can Solve a Geometry Problem too 线段相交
2013-08-07 10:48
435 查看
#include <iostream> #include <cstdio> using namespace std; struct node { double xs, ys; double xe, ye; }p[231]; double Ijs(int i, double x, double y) { return (p[i].xs-x) * (p[i].ye-y) - (p[i].ys-y) * (p[i].xe-x); } bool Iseg(int i, int j) { if(min(p[i].xs, p[i].xe) <= max(p[j].xs, p[j].xe) && min(p[i].ys, p[i].ye) <= max(p[j].ys, p[j].ye) && min(p[j].xs, p[j].xe) <= max(p[i].xs, p[i].xe) && min(p[j].ys, p[j].ye) <= max(p[i].ys, p[i].ye) && Ijs(i, p[j].xs, p[j].ys) * Ijs(i, p[j].xe, p[j].ye) <= 0 && Ijs(j, p[i].xs, p[i].ys) * Ijs(j, p[i].xe, p[i].ye) <= 0) return true; return false; } int main() { int n; while(scanf("%d", &n) != EOF && n) { for(int i = 0; i < n; i++) scanf("%lf%lf%lf%lf", &p[i].xs, &p[i].ys, &p[i].xe, &p[i].ye); int sum = 0; for(int i = 0; i < n-1; i++) for(int j = i+1; j < n; j++) if(Iseg(i, j)) sum++; cout << sum << endl; } }
相关文章推荐
- HDU 1086 You can Solve a Geometry Problem too(水题,判断线段相交)
- HDU 1086 You can Solve a Geometry Problem too(判断两线段是否相交)跨立实验
- hdu 1086 A - 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 线段相交
- HDU-#1086 You can Solve a Geometry Problem too(线段相交判定)