2010年9月26日 星期日

ACM 375 - Inscribed Circles and Isosceles Triangles

#include <stdio.h>
#include <math.h>
double B, H, SL, S, area, r, HSub2R, cycleLen;

int main()
{
double PI = 2*acos(0.0);
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i ++)
{
cycleLen = 1e-12;
scanf("%lf %lf", &B, &H);
B += 1e-15; H += 1e-15;
SL = (double)sqrt( (H*H) + (B*B/4) );
area = B * H / 2;
r = 2 * area / (SL+SL+B);
while (r >= 0.000001)
{
cycleLen += 2 * r * PI;
HSub2R = H - 2 * r;
r *= HSub2R / H;
H = HSub2R;
}
if (i != 0) printf("\n");
printf("%13.6lf\n", cycleLen);
}
return 0;
}

回目錄
回首頁

沒有留言 :

張貼留言

Related Posts Plugin for WordPress, Blogger...