51Nod 1264 线段相交







http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1264











分析:

利用向量的叉积    若有一条线段为AB   两个点C、D   如果这两个点在线段AB的两侧    那么向量AB×向量AC与向量AB×向量AD的结果正好一正一负   因为它们相乘所得到的向量方向相反    利用这个性质判断点AB是否在线段CD两侧并且点CD是否在选段AB两侧同时满足即相交     向量叉乘公式   设两向量分别为    a(x1,y1)   b(x2,y2)    则    a×b=x1*y2-x2*y1








AC代码:

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include<list>
#include <bitset>
#include <climits>
#include <algorithm>
#define mset(a,x) memset(a,x,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define FIN     freopen("input","r",stdin)
#define FOUT    freopen("output","w",stdout)
typedef long long LL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
using namespace std;
struct node{
    double x,y;
}A,B,C,D;
double cal(node a,node b,node c){
    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
int main (){
    int t;
    scanf ("%d",&t);
    while (t--){
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&D.x,&D.y);
        if (cal(A,B,C)*cal(A,B,D)<=0&&cal(C,D,A)*cal(C,D,B)<=0) printf ("Yes\n");
        else printf ("No\n");
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值