Advertisement
osipyonok

1508

May 20th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.36 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define INF 1000010000
  4. #define nl '\n'
  5. #define pb push_back
  6. #define ppb pop_back
  7. #define mp make_pair
  8. #define fi first
  9. #define se second
  10. #define pii pair<int,int>
  11. #define pdd pair<double,double>
  12. #define all(c) (c).begin(), (c).end()
  13. #define SORT(c) sort(all(c))
  14. #define rep(i,n) for( int i = 0; i < n; ++i )
  15. #define repi(i,n) for( int i = 1 ; i <= n; ++i )
  16. #define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
  17. #define repf(j,i,n) for( int j = i ; j < n ; ++j )
  18. #define die(s) {std::cout << s << nl;}
  19. #define dier(s) {std::cout << s; return 0;}
  20. #define vi vector<int>
  21. typedef long long ll;
  22. #define eps (1.0e-10)
  23. #define MAX_N 50
  24.  
  25. using namespace std;
  26.  
  27. typedef complex< double > point, vec;
  28.  
  29. inline bool eq(const double &a, const double &b){
  30.     return fabs(a - b) < eps;
  31. }
  32.  
  33. inline double dist(const point &a, const point &b){
  34.     return abs(a - b);
  35. }
  36.  
  37. inline double cross(const vec &a, const vec &b){
  38.     return (a.real() * b.imag() - a.imag() * b.real());
  39. }
  40. inline point intersection(const point &a1, const point &a2, const point &b1, const point &b2){
  41.     vec b = b2 - b1;
  42.     vec a = a2 - a1;
  43.     return a1 + (cross(b , b1 - a1) / cross(b , a)) * a;
  44. }
  45. inline point rotp(const point& p, double theta){
  46.     return p * exp(point(0 , theta));
  47. }
  48. void DivideCircle(double r, int n, point *v){
  49.     rep(i , n)  v[i] = rotp(point(0 , r) , (i * M_PI) / (n / 2));
  50. }
  51. inline double AreaOfRegularPolygon(double r, int n_even){
  52.     return (n_even / 2) * (r * r * sin( M_PI / (n_even / 2)));
  53. }
  54. inline double AreaOfRoseWindow(double *r, int n, int k){
  55.     if(n/2 == k)    return M_PI*r[k]*r[k] - AreaOfRegularPolygon(r[--k] , n);
  56.     return AreaOfRegularPolygon(r[k] , n) - AreaOfRegularPolygon(r[k - 1] , n);
  57. }
  58. int main(){
  59.     ios_base::sync_with_stdio(false);
  60.     cin.tie(NULL);
  61.     cout.precision(0);
  62.     int m;
  63.     cin >> m;
  64.     rep(j , m){
  65.         double r;
  66.         int n,k;
  67.         point p[MAX_N];            
  68.         double kr[MAX_N];              
  69.         pair<point , point> v0[MAX_N];
  70.         pair<point , point> v1[MAX_N];
  71.         cin >> r >> n >> k;
  72.         DivideCircle(r , n , p);   
  73.         rep(i , n / 2){
  74.             v0[i].fi = p[0];
  75.             v0[i].se = p[n / 2 + i];
  76.             v1[i].fi = p[1];
  77.             v1[i].se = p[(n / 2 + i + 1) % n];
  78.         }
  79.         repf(i , 1 , n / 2){
  80.             point q = intersection(v0[i].fi , v0[i].se , v1[i].fi , v1[i].se);
  81.             kr[i] = abs(q);
  82.         }
  83.         kr[0] = 0.;
  84.         kr[n / 2] = r;
  85.         printf("%.4lf\n" , AreaOfRoseWindow(kr , n ,k));
  86.     }
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement