51NOD1264线段相交

来源:互联网 发布:淘宝联盟怎么合并付款 编辑:程序博客网 时间:2024/05/20 09:09

题目链接:点击打开链接


解题思路:

  用直线和点的关系来判断.把A和B这条线段看成一条直线,分别看C和D关于这条直线的位置关系,如果一正一负,那么必然相交.

完整代码:

#include <algorithm>#include <iostream>#include <cstring>#include <climits>#include <cstdio>#include <string>#include <cmath>#include <set>#include <queue>#include <map>#include <vector>#include <cstdlib>#include <stack>#include <time.h>using namespace std;typedef long long LL;const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const double EPS = 1e-9;const double PI = acos(-1.0); //M_PI;const int maxn = 100001;struct point{        double x , y;        point(double a , double b) : x(a) , y(b) {};        point() {};        void input()        {                scanf("%lf%lf",&x,&y);        }};bool line_make_point(point a , point b , point c , point d){        double C = (c.y - a.y) * (a.x - b.x) - (a.y - b.y) * (c.x - a.x);        double D = (d.y - a.y) * (a.x - b.x) - (a.y - b.y) * (d.x - a.x);        if(C * D > 0)   return false;        return true;}bool check(point a , point b , point c , point d){        if(!line_make_point(a , b , c , d))     return false;        if(!line_make_point(c , d , a , b))     return false;        return true;}int main(){#ifdef DoubleQ    freopen("in.txt","r",stdin);#endif    int T;    scanf("%d",&T);    while(T--)    {            struct point a , b , c , d;            a.input();            b.input();            c.input();            d.input();            if(check(a , b , c , d))                printf("Yes\n");            else                printf("No\n");    }    return 0;}/***************************************************   Copyright By DoubleQ*   Written in 2015*   Blog Address : zhanghe.ac.cn*                  http://blog.csdn.net/u013447865*   Email Address: acmer_doubleq@qq.com**************************************************/


0 0
原创粉丝点击