Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- int main()
- {
- int t;
- scanf("%d", &t);
- while(t--)
- {
- int r, h, a, b;
- scanf("%d%d%d%d", &r, &h, &a, &b);
- double delta = 1e-5;
- double area = 0.0;
- double y = 0.0;
- double volumeIntersect = 0.0;
- do
- {
- double c = (y * (a+b)) /(2*r*(h-y));
- double d = (r - r * y / h);
- double e = 2 * std::acos(c) * d * d;
- double f = y * (a+b) / (2*h);
- double g = std::sqrt(d * d - f * f) * y * (a+b) / h;
- area = (e - g);
- volumeIntersect += area * delta;
- y += delta;
- } while (area - delta > 0);
- double volume = 2.0 * h * r * r * M_PI / 3.0;
- printf("%f\n",volume - volumeIntersect);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement