hdu 3668 几何题
就是考数学,考空间想象力,唉,数学还是不行啊,弄了两三个小时才勉强做出来……
/*
* hdu3668/win.c
* Created on: 2011-8-24
* Author : ben
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define PI 3.1415926535
/**计算图形中那个特殊形体的体积的公式*/
double formular(double r, double t) {
return r * r * t - t * t * t / 3;
}
void work() {
int H, R;
double ans, temp;
while(scanf("%d%d", &R, &H) == 2) {
ans = 2.0 * PI * R * R * H;
if(2 * R <= H) {
ans = ans - 8 * (formular(R, R) - formular(R, 0));
}else {
temp = sqrt(R * R - H * H / 4.0);
ans = ans - 8 * (formular(R, R) - formular(R, temp)) - 2.0 * H * H * temp;
}
printf("%.4lf\n", ans);
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
work();
return 0;
}