Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KT-Yeh/8912317 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8912317 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
double B, H;
const double pi = 2 * asin(1);
int Case;
scanf("%d", &Case);
while (Case--){
scanf("%lf %lf", &B, &H);
double C = 0;
while (1){
double T = hypot(B/2, H);
double R = (B*H)/(2*T+B); // 2TR+BR = BH
if (R < 0.000001) break;
C += (2 * pi * R);
double H_tmp = H - 2*R;
B = B * (H_tmp / H);
H = H_tmp;
}
printf("%13.6f\n", C);
if (Case) printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment