fork download
  1. // Author: Sahil Yasar
  2.  
  3. // #include <bits/stdc++.h>
  4. #include <iostream>
  5. #include <cmath>
  6. #include <iomanip>
  7. using namespace std;
  8. #define endl '\n'
  9.  
  10. // #include <ext/pb_ds/assoc_container.hpp>
  11. // #include <ext/pb_ds/tree_policy.hpp>
  12. // using namespace __gnu_pbds;
  13. // template<class T>
  14. // using oset = tree<T, null_type, less<T>, rb_tree_tag,
  15. // tree_order_statistics_node_update>;
  16. // template <class K, class V> using ht = gp_hash_table<K, V>;
  17.  
  18. template <class T1, class T2> ostream& operator<<(ostream& out, const pair<T1, T2> p)
  19. { return out<<'('<<p.first<<", "<<p.second<<")"; }
  20. template <class ...Args> auto &print(const Args &...args)
  21. { return ((cerr<<args<<", "), ...)<<"\b\b)"<<endl; }
  22. #define watch(...) if(true){cerr<<"("#__VA_ARGS__") = ("; print(__VA_ARGS__);}
  23.  
  24. #define all(x) x.begin(), x.end()
  25. #define rall(x) x.rbegin(), x.rend()
  26. #define sz(x) (int)x.size()
  27. #define f first
  28. #define s second
  29. #define read(arr) for(auto& x: arr) cin>>x
  30. #define write(arr) for(auto& x: arr) cout<<x<<" "; cout<<endl
  31. #define mem(x, n) memset(x, n, sizeof(x))
  32. #define getUnique(x) sort(all(x)); x.erase(unique(all(x)), x.end());
  33.  
  34. typedef long long ll;
  35. typedef long double ld;
  36. typedef unsigned long long ull;
  37. typedef pair<int, int> pii;
  38. typedef pair<ll, ll> pll;
  39.  
  40. const double PI = acos(-1);
  41.  
  42. int main(){
  43. cin.tie(0)->sync_with_stdio(0);
  44. cin.exceptions(cin.failbit);
  45.  
  46. int t, nt, at, nb, ab;
  47. double theta, alpha, beta, ans, rt, rb, x, p, c, a, len;
  48. cout<<fixed<<setprecision(6);
  49. cin>>t;
  50. while(t--){
  51. cin>>nt>>at>>nb>>ab;
  52.  
  53. theta = 2 * PI / nb;
  54. alpha = (PI - theta)/2;
  55. x = sin(alpha)/sin(theta) * ab;
  56. rb = sqrt(x*x - ab*ab/4.0); // Radius of of inscribed circle of bottom polygon
  57. p = nb/2.0 * x*x * sin(theta); // Area of bottom polygon
  58.  
  59. theta = 2 * PI / nt;
  60. alpha = (PI - theta)/2;
  61. x = sin(alpha)/sin(theta) * at;
  62. rt = sqrt(x*x - at*at/4.0); // Radius of of inscribed circle of top polygon
  63. c = PI*rt*rt; // Area of inscribed circle of top polygon
  64.  
  65. a = len = 0;
  66. if (rt > rb){
  67. len = 2*sqrt(rt*rt - rb*rb);
  68. if (len <= ab){
  69. beta = 2*acos(rb/rt);
  70. a = beta/2*rt*rt - rb*len/2; // For inclusion exclusion
  71. }
  72. }
  73.  
  74. ans = (len > ab)? 0: p-c+nb*a;
  75. cout<<ans<<endl;
  76. }
  77.  
  78. return 0;
  79. }
  80.  
Success #stdin #stdout 0.01s 5288KB
stdin
6
5 5
4 6
10 6
11 5
11 6
13 8
10 10
12 8
3 1
3 1
1000 1000
1000 1000
stdout
2.820131
0.000000
515.943499
0.201572
0.171213
261798.698746