[51nod]1264 线段相交
2016-07-02 12:46
288 查看
题目链接点这里
判断两线段相交
直接上模板
#include<cstring> #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> using namespace std; const double eps=1e-8; const double pi=acos(-1.0); int sgn(double x){ if(fabs(x)<eps) return 0; if(x<0) return -1; else return 1; } struct node { double x,y; node(){} node(int x_,int y_) { x=x_; y=y_; } node operator -(const node &b) { return node(x-b.x,y-b.y); } double operator *(const node &b) { return x*b.x+y*b.y; } double operator ^(const node &b) { return x*b.y-b.x*y; } friend istream & operator >>(istream &in,node & a) { in>>a.x>>a.y; return in; } } p[4]; typedef node vect; struct line { node s,e; line(){} line(const node &s_,const node &e_) { s=s_; e=e_; } friend bool inter(line l1,line l2) { return max(l1.s.x,l1.e.x)>=min(l2.s.x,l2.e.x) && max(l2.s.x,l2.e.x)>=min(l1.s.x,l1.e.x) && max(l1.s.y,l1.e.y)>=min(l2.s.y,l2.e.y) && max(l2.s.y,l2.e.y)>=min(l1.s.y,l1.e.y) && sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s-l1.e))<=0 && sgn((l1.s-l2.e)^(l2.s-l2.e))*sgn((l1.e-l2.e)^(l2.s-l2.e))<=0; } }; typedef line segment; int main() { segment l1,l2; int sk; scanf("%d",&sk); while(sk--) { cin>>l1.s>>l1.e>>l2.s>>l2.e; if(inter(l1,l2)) puts("Yes"); else puts("No"); } }
相关文章推荐
- [51nod]1265 四点共面
- [51nod]1298 圆与三角形
- 3个数和为0
- 51nod 1770 数数字
- 51nod 1459 迷宫游戏
- 51nod 1001 数组中和等于K的数对
- 51Nod 大数乘法
- 51Nod A^BmodC
- 51Nod 逆序数
- 51NOD 1020 逆序排列
- 51nod 算法马拉松11 A 翻硬币
- 51nod(1264)——线段相交
- 51nod(1183)——dp
- 动态规划初步总结(1)(51Nod,CODE[VS]为例题)
- 51Nod 1086 背包问题 V2(二进制多重背包)
- 51nod 1241 特殊的排序 最少移动次数
- 51nod 可能的路径
- 51nod 1065 最小正子段和(最小正字段和)
- 51nod 1405 树的距离之和 (两次dfs,树形dp)
- 51nod 锁屏密码