题意:
给定一个边长为$n$的正方形,求阴影部分面积
思路:
现将图形顺时针旋转 $45°$ 然后建立坐标系,写出阴影部分方程,用$Simpson$积分算一下就行了,注意精度,$1e^{-10}$ $WA$ 了 ,$1e^{-20}$ $A$了
1 #include<bits/stdc++.h> 2 3 using namespace std; 4 5 #define X first 6 #define Y second 7 #define eps 1e-20 8 #define gcd __gcd 9 #define pb push_back 10 #define PI acos(-1.0) 11 #define lowbit(x) (x)&(-x) 12 #define bug printf("!!!!! "); 13 #define mem(x,y) memset(x,y,sizeof(x)) 14 15 typedef long long LL; 16 typedef long double LD; 17 typedef pair<int,int> pii; 18 typedef unsigned long long uLL; 19 20 const int maxn = 1e5+2; 21 const int INF = 1<<30; 22 const int mod = 1e9+7; 23 24 double f(double x){ 25 return sqrt(1-x*x) - sqrt(4 - x*x) + sqrt(2); 26 } 27 double simpson(double L ,double R){ 28 return (R-L)*(f(L)+4.0*f((L+R)/2.0)+f(R))/6.0; 29 } 30 double asr(double L,double R){ 31 double mid = (L+R)/2.0; 32 double res = simpson(L,R); 33 double left = simpson(L,mid),right = simpson(mid,R); 34 if(fabs(left+right-res)<eps)return left + right; 35 else return asr(L,mid)+asr(mid,R); 36 } 37 double C; 38 void solve(){ 39 int n; 40 scanf("%d",&n); 41 printf("%.2f ",n*n*1.0*C); 42 return; 43 } 44 45 int main() 46 { 47 // freopen("in.txt","r",stdin); 48 // freopen("out.txt","w",stdout); 49 // ios::sync_with_stdio(false); 50 int t = 1; 51 scanf("%d",&t); 52 C = asr(0,sqrt(7.0/8.0)); // 离线计算单位系数 53 while(t--){ 54 // printf("Case %d: ",cas++); 55 solve(); 56 } 57 return 0; 58 }