51nod1264 线段相交

来源:互联网 发布:js 截取字符串后几位 编辑:程序博客网 时间:2024/05/18 05:01
给出的数据应该不包含在一条线上,下面的程序也过不了那样的数据。
#include <bits/stdc++.h>using namespace std;struct point{    double x,y;}p[4];double f(point a,point b,point c){    return (a.x - c.x)*(b.y - c.y)-(a.y - c.y)*(b.x - c.x);}bool check(){    if(f(p[1],p[2],p[0])*f(p[3],p[1],p[0]) < 0)        return false;    if(f(p[1],p[2],p[3])*f(p[2],p[0],p[3]) < 0)        return false;    return true;}int main(){    int T;    scanf("%d",&T);    while(T--)    {        for(int i = 0;i < 4;i++)            scanf("%lf%lf",&p[i].x,&p[i].y);        if(check())            printf("Yes\n");        else            printf("No\n");    }    return 0;}

原创粉丝点击