#include <iostream>
#include <math.h>
using namespace std;
#define MIN 0.001
#define PI acos(-1)
typedef struct node
{
int R, L;
}ST_CYC;
ST_CYC cyclind[15];
/*这里求圆切面的面积*/
double cal_v(int rr, double h, int L)
{
double t, c, s, alpha;
double R = (double)rr;
s = PI * R * R;
alpha = 2.0 * acos(fabs(h - R) / R);
if (h < 2.0 * R && h > R)
{
s -= s * (alpha / (2.0 * PI));
s += 0.5 * R * R * sin(alpha);
}
else if (h / 2.0 < rr)
{
s *= (alpha / (2.0 * PI));
s -= 0.5 * R * R * sin(alpha);
}
return s * (double)L;
}
/*二分查找满足条件的值*/
double bin_find(int size, int max_R, double target)
{
int i;
double low, high, mid, V;
high = 2 * max_R;
low = 0;
while (1)
{
mid = (low + high) / 2.0;
V = 0;
for (i=0 ; i<size ; i++)
V += cal_v(cyclind[i].R, mid, cyclind[i].L);
if (fabs(V - target) < MIN)
break;
if (V < target)
low = mid;
else
high = mid;
}
return mid;
}
double all_v(int size)
{
int i;
double v = 0;
for (i=0 ; i<size ; i++)
v += cal_v(cyclind[i].R, cyclind[i].R * 2, cyclind[i].L);
return v;
}
int main(int argc, char *argv[])
{
int n, i, max_R;
double V, ret;
while (EOF != scanf("%d ", &n))
{
max_R = 0;
for (i=0 ; i<n ; i++)
{
cin >> cyclind[i].R >> cyclind[i].L;
if (cyclind[i].R > max_R)
max_R = cyclind[i].R;
}
V = all_v(n);
ret = bin_find(n, max_R, V / 2.0);
printf("%.3lf\n", ret);
}
}
|