HDU 4798 Skycity【几何】

来源:互联网 发布:javascript怎么读 编辑:程序博客网 时间:2024/06/09 19:24

题目链接

题意:有个圆台型建筑物,最上面的圆的半径是r,最下面的圆的半径是R,高度为H,有F层,现在给每层的四周贴玻璃,要贴成正多边形的玻璃,且每块玻璃的面积不能小于S。求玻璃的总的最小面积。

首先玻璃的长度越小肯定总面积越小,而每层的高度可以算出来,所以最小的长度可以知道。通过几何可以算出需要多少块玻璃。但是由于不一定能整除,块数n会偏小,所以要再从n倒推真正的玻璃长度,从而算出答案。还有一个要注意的地方就是它是绕着天花板贴的。

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const double pi = acos(-1);double R, r, H, F, S;double cal(double r, double h){    int n = pi / atan(S / (2 * r * h));    return 2 * n * r * tan(pi / n);}int main(){    while (scanf("%lf %lf %lf %lf %lf", &R, &r, &H, &F, &S) != EOF)    {        double h = H / F;        double ans = 0.0;        // ans += h * cal(R, h);绕着天花板贴的        ans += h * cal(r, h);        for (double i = 1; i <= F - 1; i++)        {            double x = (R - r) * i / F + r;            ans += cal(x, h) * h;        }        printf("%.3f\n", ans);    }}