zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    A
    N
    M
    L
    K
    J
    sass
    通过ps给透明通道的图片添加灰度(适用于需要兼容IE7,效果很好)
    CSS十一问——好奇心+刨根问底=CSSer
    清除浮动的7种方法
  • 原文地址:https://www.cnblogs.com/naix-x/p/3359653.html
Copyright © 2011-2022 走看看