杭电 2289 Cup 解题报告

    几何题,求圆锥体积差不多的题,难度不大,要注意的是杯子口半径R>=杯底半径r。下面是笔者的代码,AC了

#include <stdio.h>
#include <math.h>

int main()
{
    int c;
    double r,R,H,V,t,P=acos(-1.0);
    scanf("%d",&c);
    while(c--)
    {
        scanf("%lf%lf%lf%lf",&r,&R,&H,&V);
        if(R==r)
            t=V/(R*R*P);
        else
        {
            t=H*r/(R-r);
            t=t*(pow(1+3*V/(P*r*r*t),0.3333333333)-1);
        }
        if(t>H)
            t=H;
        printf("%.6f\n",t);
    }
}

    然后在static里看到有代码长度是240B的,吓坏我了。。。0MS,208K,240B,几乎是奇迹啊。

    然后笔者就挑战了一下,精简到几乎不能精简的地步,终于到237B,0MS了。。。代码如下,AC了,但是非常不好看。。。

#include<stdio.h>
#include<cmath>
int main(){int c;double r,R,H,V,t,P=3.14159265;scanf("%d",&c);while(c--){scanf("%lf%lf%lf%lf",&r,&R,&H,&V);if(R==r) t=V/r/r/P;else{t=H/(R/r-1);t*=pow(1+V*3/P/r/r/t,1.0/3)-1;}printf("%.6f\n",t>H?H:t);}}

    反正笔者是精简不了了,贴个图纪念一下。感觉挺虚荣的Orz

posted @ 2013-02-12 21:58  SF-_-  阅读(162)  评论(0编辑  收藏  举报