码迷,mamicode.com
首页 > 其他好文 > 详细

hdu_1086

时间:2015-03-01 06:48:41      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

发现自己连向量的点乘都不会算了

 

跨立实验

 

#include <cstdio>

#define MAXN 100

struct point
{
    double x, y;
    point operator - (point temp) const
    {
        point res;
        res.x = temp.x - x;
        res.y = temp.y - y;
        return res;
    }
    double operator * (point temp) const
    {
        return x*temp.y - temp.x*y;
    }
};

int IsIntersect(point a1, point a2, point b1, point b2)
{
    double d1 = (a2-a1)*(b1-a1);
    double d2 = (a2-a1)*(b2-a1);
    double d3 = (b2-b1)*(a1-b1);
    double d4 = (b2-b1)*(a2-b1);
    if(d1*d2<=0 && d3*d4<=0)
        return 1;
    return 0;
}

point be[MAXN+10], en[MAXN+10];

int main(int argc, char const *argv[])
{
    // freopen("in", "r", stdin);
    int n;
    while(scanf("%d", &n) && n){
        int intersections = 0;
        //  input
        for(int i = 1; i <= n; ++i)
            scanf("%lf %lf %lf %lf", &be[i].x, &be[i].y, &en[i].x, &en[i].y);
        // solve
        for(int i = 1; i <= n; ++i)
            for(int j = i+1; j <= n; ++j)
                intersections += IsIntersect(be[i], en[i], be[j], en[j]);
        // print
        printf("%d\n", intersections);
    }
    return 0;
}

 

hdu_1086

标签:

原文地址:http://www.cnblogs.com/takeoffyoung/p/4306553.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!