IT民工
加油!

算是学了一个模版吧

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

const double eps = 1e-8;
struct point
{
    double x, y;
};

point a, b, c, d;

inline int dcmp(double d)
{
    if(fabs(d) < eps) return 0;
    return d > 0 ? 1 : -1;
}

inline double det(double x1, double y1, double x2, double y2)
{
    return x1 * y2 - x2 * y1;
}

inline double cross(point a, point b, point c)
{
    return det(b.x - a.x, b.y - a.y, c.x - a.x, c.y - a.y);
}

inline int segcross(point a, point b, point c, point d)
{
    return ((dcmp(cross(a, c, d)) ^ dcmp(cross(b, c, d))) == -2
        &&  (dcmp(cross(c, a, b)) ^ dcmp(cross(d, a, b))) == -2);

}

int main()
{
    while(scanf("%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y) != EOF)
    {
        scanf("%lf%lf%lf%lf", &c.x, &c.y, &d.x, &d.y);
        if(segcross(a, b, c, d))
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}
posted on 2012-08-07 10:01  找回失去的  阅读(241)  评论(0编辑  收藏  举报