Skip to content

Instantly share code, notes, and snippets.

@vo
Created December 24, 2016 02:31
Show Gist options
  • Save vo/8050289b5c2719f799c52f885b04655a to your computer and use it in GitHub Desktop.
Save vo/8050289b5c2719f799c52f885b04655a to your computer and use it in GitHub Desktop.
Programming Practice: The Laurel-Hardy Story
#include <iostream>
#include <cmath>
#include <iomanip>
double compute_h2(double r, double d, double h1) {
double t = -2.0 * std::acos((r - d) / r);
double x = std::sqrt(r * r - (r - h1) * (r - h1));
return ((h1 - r) * std::cos(t)) + (x * std::sin(t)) + r;
}
int main() {
std::size_t N;
while(std::cin >> N) {
for (int i = 1; i <= N; ++i) {
int r, d, h1;
std::cin >> r >> d >> h1;
std::cout << "Case " << i << ": "
<< std::fixed << std::setprecision(4)
<< compute_h2(r, d, h1) << std::endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment