[51nod]1298 圆与三角形
2016-07-02 09:36
375 查看
https://www.51nod.com/onlineJudge/questionCode.html#problemId=1298¬iceId=54853
判断圆与三角形是否相交,转化为判断点到线段的最小距离。
1A
要整理模板
#include<cstring> #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> using namespace std; const double eps=1e-8; 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; } } p,a[3]; double r; int sgn(double x) { if(fabs(x)<eps) return 0; if(x>0) return 1; else return -1; } double dist(const node &a,const node &b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } double point_to_seg(node p,node a,node b) { double y=(p-a)*(b-a); if(sgn(y)<=0) return dist(a,p); if(sgn(y-dist(a,b))>=0) return dist(b,p); double s=(p-a)^(b-a); return s*s/dist(a,b); } bool ok() { for(int i=0;i<3;i++) { int x=sgn(dist(a[i],p)-r*r); int y=sgn(dist(a[(i+1)%3],p)-r*r); if(x*y==0 || x*y==-1) return true; if(x<0 && y<0) continue; if(sgn(point_to_seg(p,a[i],a[(i+1)%3])-r*r)<=0) return true; } return false; } int main() { int sk; scanf("%d",&sk); while(sk--) { scanf("%lf%lf%lf",&p.x,&p.y,&r); for(int i=0;i<3;i++) { scanf("%lf%lf",&a[i].x,&a[i].y); } puts(ok()?"Yes":"No"); } }
相关文章推荐
- 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 锁屏密码
- 51nod 1495 中国好区间
- 51nod 1443 路径和树