• HDU 4454 Stealing a Cake(枚举角度)


    题目链接

    去年杭州现场赛的神题。。枚举角度。。精度也不用注意。。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <vector>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    #define eps 1e-8
    #define PI 3.1415926
    double xl,xr,yl,yr;
    double judge(double tx,double ty)
    {
        if(tx < xl&&ty < yl)
        return sqrt((tx-xl)*(tx-xl)+(ty-yl)*(ty-yl));
        else if(tx >= xl&&tx <= xr&&ty >= yr)
        return ty - yr;
        else if(tx >= xl&&tx <= xr&&ty <= yl)
        return yl - ty;
        else if(tx > xr&&ty > yr)
        return sqrt((tx-xr)*(tx-xr)+(ty-yr)*(ty-yr));
        else if(ty >= yl&&ty <= yr&&tx >= xr)
        return tx - xr;
        else if(ty >= yl&&ty <= yr&&tx <= xl)
        return xl - tx;
        else if(tx > xr&&ty < yl)
        return sqrt((tx-xr)*(tx-xr)+(ty-yl)*(ty-yl));
        else if(tx < xl&&ty > yr)
        return sqrt((tx-xl)*(tx-xl)+(ty-yr)*(ty-yr));
        return 10000000;
    }
    int main()
    {
        double sx,sy,rx,ry,r;
        int i;
        double tx,ty,minz,temp;
        while(scanf("%lf%lf",&sx,&sy)!=EOF)
        {
            if(sx == 0&&sy == 0) break;
            minz = 1000000000;
            scanf("%lf%lf%lf",&rx,&ry,&r);
            scanf("%lf%lf%lf%lf",&xl,&yl,&xr,&yr);
            if(xl > xr) swap(xl,xr);
            if(yl > yr) swap(yl,yr);
            for(i = 0;i < 36000;i ++)
            {
                tx = rx+r*cos(i*1.0*PI/18000);
                ty = ry+r*sin(i*1.0*PI/18000);
                temp = sqrt((tx-sx)*(tx-sx) + (ty-sy)*(ty-sy));
                minz = min(minz,temp+judge(tx,ty));
            }
            printf("%.2f
    ",minz);
        }
        return 0;
    }
  • 相关阅读:
    重载函规则
    lambd
    内联函数
    c和c++中的枚举和 区别
    关于于c++中的类型转换
    作用域解析运算符
    day01
    二级指针输入特性
    二级指针的 数出特性
    influence maximization 第二弹
  • 原文地址:https://www.cnblogs.com/naix-x/p/3359653.html
Copyright © 2020-2023  润新知