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

求出圆心到三条线段的最短距离,然后判断是否有顶点在圆外,就把全部情况举出来。

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const double PI = acos(-1.0);
double torad(double deg) { return deg/ * PI; } struct Point
{
double x, y;
Point(double x=, double y=):x(x),y(y) { }
}; typedef Point Vector; Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x+B.x, A.y+B.y); }
Vector operator - (const Point& A, const Point& B) { return Vector(A.x-B.x, A.y-B.y); }
Vector operator * (const Vector& A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (const Vector& A, double p) { return Vector(A.x/p, A.y/p); } bool operator < (const Point& a, const Point& b) //结构体运算符的重载
{
return a.x < b.x || (a.x == b.x && a.y < b.y);
} const double eps = 1e-;
int dcmp(double x) { if(fabs(x) < eps) return ; else return x < ? - : ; } bool operator == (const Point& a, const Point &b)
{
return dcmp(a.x-b.x) == && dcmp(a.y-b.y) == ;
} //基本运算:
double dist(const Vector& A, const Vector& B) {return sqrt(pow(A.x-B.x,)+pow(A.y-B.y,));}
double Dot(const Vector& A, const Vector& B) { return A.x*B.x + A.y*B.y; }
double Length(const Vector& A) { return sqrt(Dot(A, A)); }
double Angle(const Vector& A, const Vector& B) { return acos(Dot(A, B) / Length(A) / Length(B)); }
double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; }
double Area2(Point A, Point B, Point C) {return Cross(B-A, C-A);} //向量旋转 rad是弧度
Vector Rotate(const Vector& A, double rad)
{
return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}
//点和直线:
//两直线的交点
Point GetLineIntersection(const Point& P, const Point& v, const Point& Q, const Point& w)
{
Vector u = P-Q;
double t = Cross(w, u) / Cross(v, w);
return P+v*t;
} //点到直线的距离
double DistanceToLine(const Point& P, const Point& A, const Point& B)
{
Vector v1=B-A, v2=P-A;
return fabs(Cross(v1,v2)) / Length(v1);
} //点到线段的距离
double DistanceToSegment(const Point& P, const Point& A, const Point& B)
{
if(A == B) return Length(P-A);
Vector v1 = B - A, v2 = P - A, v3 = P - B;
if(dcmp(Dot(v1, v2)) < ) return Length(v2);
else if(dcmp(Dot(v1, v3)) > ) return Length(v3);
else return fabs(Cross(v1, v2)) / Length(v1);
} //点在直线上的投影
Point GetLineProjection(const Point &P, const Point &A,const Point &B)
{
Vector v = B - A;
return A+v*(Dot(v, P-A) / Dot(v, v));
} //线段相交判定
bool SegmentProperIntersection(const Point& a1, const Point& a2, const Point& b1, const Point& b2)
{
double c1 = Cross(a2-a1,b1-a1), c2 = Cross(a2-a1,b2-a1),
c3 = Cross(b2-b1,a1-b1), c4=Cross(b2-b1,a2-b1);
return dcmp(c1)*dcmp(c2)< && dcmp(c3)*dcmp(c4)<;
} //判断点在线段上(两个端点除外)
bool OnSegment(const Point& p, const Point& a1, const Point& a2)
{
return dcmp(Cross(a1-p, a2-p)) == && dcmp(Dot(a1-p, a2-p)) < ;
} int main()
{
freopen("a.txt","r",stdin);
int t;
Vector s,p[];
double r,x;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf",&s.x,&s.y,&r);
for(int i=;i<;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
int ans=;
x=DistanceToSegment(s,p[],p[]);
if(x<=r) ans++;
x=DistanceToSegment(s,p[],p[]);
if(x<=r) ans++;
x=DistanceToSegment(s,p[],p[]);
if(x<=r) ans++;
bool flag=;
for(int i=;i<;i++)
{
if(dist(s,p[i])>r)
{
flag=;break;
}
}
// printf("%d %d\n",ans,flag);
if(ans>=&&flag) puts("Yes");
else puts("No");
}
return ;
}

最新文章

  1. 11.11光棍节工作心得——github/MVP
  2. Linux 内核常见宏定义
  3. 第二次C语言作业
  4. Android Studio 入门指南
  5. Oracle存储过程中传入参数,传出字符串
  6. conn,stmt,rset 的关闭(规范)
  7. 使用HttpURLConnection下载文件时出现 java.io.FileNotFoundException彻底解决办法
  8. ibatis把表名作为一个参数报错问题的解决方案
  9. 队列(链式存储)JAVA代码
  10. JS获取select的值
  11. asp.net后台的一些操作
  12. Android App开发常用专题开源代码
  13. win10快捷键大全
  14. Java Selenium 定位元素 实现的一个注册功能
  15. Going from u to v or from v to u? POJ - 2762(强连通 有向最长路径)
  16. REST架构简析(原论文整理)
  17. Oracle EBS FORM 更改记录状态
  18. 【原创】大叔问题定位分享(31)hive metastore报错
  19. Spring MVC基础知识整理➣数据校验与格式化
  20. pip install whl

热门文章

  1. 对于JS == 运算的一些理解
  2. 微软最新的Web服务器Katana发布了版本3
  3. spring常用注解笔记
  4. absolute元素水平居中
  5. Android BitmapFactory.decodeFile(filePath, options) 返回 Null 6.0权限
  6. Xamarin.Forms跨平台开发入门-第二部分:深入解析
  7. spring-mvc hello world (1)
  8. Record these plug-ins of vscode
  9. iTOP-4418/6818开发板支持锂电池供电方案
  10. vue vueRouter vuex Axios webpack 前端常用内容