HDU_1086 You can Solve a Geometry Problem too(几何题)
2011-08-12 17:17
465 查看
计算几何讲解:http://dev.gameres.com/Program/Abstract/Geometry.htm#判断两线段是否相交
一个比较好的范例:http://www.wutianqi.com/?p=2407
代码:
一个比较好的范例:http://www.wutianqi.com/?p=2407
代码:
#include <stdio.h> struct node { double x1, y1; double x2, y2; }l[110]; double X(double a, double b, double c, double d) { return a*d - b*c; } int judge(int i, int j) { double a = X(l[i].x1-l[j].x1, l[i].y1-l[j].y1, l[j].x2-l[j].x1, l[j].y2-l[j].y1); double b = X(l[i].x2-l[j].x1, l[i].y2-l[j].y1, l[j].x2-l[j].x1, l[j].y2-l[j].y1); double c = a*b; double d = X(l[j].x1-l[i].x1, l[j].y1-l[i].y1, l[i].x2-l[i].x1, l[i].y2-l[i].y1); double e = X(l[j].x2-l[i].x1, l[j].y2-l[i].y1, l[i].x2-l[i].x1, l[i].y2-l[i].y1); double f = d*e; if(c <= 0 && f <= 0) return 1; return 0; } int main() { int n, i, j; //freopen("data.in", "r", stdin); while(scanf("%d", &n), n) { int ans = 0; for(i = 1; i <= n; i++) scanf("%lf%lf%lf%lf", &l[i].x1, &l[i].y1, &l[i].x2, &l[i].y2); for(i = 1; i < n; i++) for(j = i+1; j <= n; j++) { if(judge(i, j)) ans++; } printf("%d\n", ans); } return 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_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