HZAU 1003 Alien invasion

原题
几何题 找公式

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
void solve()
{
  double d, r;
  cin >> d >> r;
  double ans = 0;
  if (d < r) {
    double a = 3 * sqrt(3) * d * d / 4;
    double b = M_PI * r * r / 2;
    double c = r * r * acos(sqrt(3) * d / (2 * r)) - sqrt(3) * d / 2 * sqrt(r * r - d * d * 3 / 4);
    ans = a - b + 3 * c;
  }
  printf("%.2lf\n", ans);
}
int main()
{
// freopen("input.txt", "r", stdin);
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    solve();
  }
}

你可能感兴趣的:(HZAU 1003 Alien invasion)