[51nod]1298 圆与三角形
来源:互联网 发布:中网数据传奇 编辑:程序博客网 时间:2024/05/02 02:27
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"); }}
0 0
- 51nod 1298 圆与三角形
- 51Nod 1298 圆与三角形
- [51nod]1298 圆与三角形
- 51nod 1298 圆与三角形
- 51nod 1298 圆与三角形
- 51nod--1298 圆与三角形
- 51nod 1298 圆与三角形
- 51NOD 1298 圆与三角形
- 圆与三角形-51NOD 1298
- 51nod oj 1298 圆与三角形
- 51nod 1298 圆与三角形
- 51NOD 1298圆与三角形
- 51Nod 1298 圆与三角形
- 51nod 1298 圆与三角形
- 51Nod-1298 圆与三角形
- 51Nod 1298 圆与三角形
- 51Nod-1298 圆与三角形
- 51 nod: 1298 圆与三角形
- synchronized和ReentrantLock的区别
- WEBGIS功能清单
- UVALive 6693 - Flow Game(点在线段上判断)
- section01
- Unity如何发布一个Android 的开发应用
- [51nod]1298 圆与三角形
- android 图片轮播
- android fragment不执行onResume,onPause
- socket穿透代理代码(C++版)
- 283. Move Zeroes
- codeforces_677C. Vanya and Label(快速幂)
- struts2 登录拦截
- java中成员变量和局部变量的初始化
- Unity中的C#学习(一)