Created
December 24, 2016 02:31
-
-
Save vo/8050289b5c2719f799c52f885b04655a to your computer and use it in GitHub Desktop.
Programming Practice: The Laurel-Hardy Story
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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