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