HDU 1221
来源:互联网 发布:淘宝天下 电话号码 编辑:程序博客网 时间:2024/05/19 03:29
这道题嘛,分析清楚,什么时候最大,什么时候最小
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;struct Point { double x, y; Point() {} Point(double x, double y) { this->x = x; this->y = y; } void read() { scanf("%lf%lf", &x, &y); }};typedef Point Vector;Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y);}const double eps = 1e-8;int dcmp(double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;}double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;} //点积double Length(Vector A) {return sqrt(Dot(A, A));} //向量的模double Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} //叉积void DistanceToSegment(Point P, Point A, Point B,double &left,double &right) { Vector v1 = B - A, v2 = P - A, v3 = P - B; if (dcmp(Dot(v1, v2)) < 0) left = Length(v2); else if (dcmp(Dot(v1, v3)) > 0) left = Length(v3); else left = fabs(Cross(v1, v2)) / Length(v1); right=max(Length(v2),Length(v3));}const double INF=1e9;int t;Point q,p[5];double r;int main(){ scanf("%d",&t); while(t--) { scanf("%lf%lf%lf",&q.x,&q.y,&r); double a,b,c,d; scanf("%lf%lf",&a,&b); scanf("%lf%lf",&c,&d); p[0].x=p[3].x=a; p[1].x=p[2].x=c; p[0].y=p[1].y=b; p[2].y=p[3].y=d; double dist_min=INF,dist_max=0.0; for(int i=0;i<4;i++){ double tmp_min=INF,tmp_max=0; DistanceToSegment(q,p[i],p[(i+1)%4],tmp_min,tmp_max); dist_min=min(dist_min,tmp_min); dist_max=max(dist_max,tmp_max); } if(dcmp(dist_min-r)>0||dcmp(dist_max-r)<0){ printf("NO\n"); continue; } else printf("YES\n"); } return 0;}
0 0
- HDU 1221
- hdu 1221 数学题
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- CSS3
- DailyLine Share
- 23种设计模式C++实例之模板方法模式
- Android 密码输入 EditText
- tjut 3037
- HDU 1221
- 面向对象
- shiro 使用缓存时出现:java.io.NotSerializableException: org.apache.shiro.util.SimpleByteSource
- 国家城市二级联动jsp页面
- 仅需五步,制作专属你的网站
- C++函数对象的应用
- Retrofit初体验
- 完全搞定iframe(框架)里的滚动条
- Java 集合框架源码分析(三)——HashMap