HDU - 5858(几何计算)


cjj is fun with math problem. One day he found a Olympic Mathematics problem for primary school students. It is too difficult for cjj. Can you solve it? 

 


Give you the side length of the square L, you need to calculate the shaded area in the picture. 


The full circle is the inscribed circle of the square, and the center of two quarter circle is the vertex of square, and its radius is the length of the square. 
Input
The first line contains a integer T(1<=T<=10000), means the number of the test case. Each case contains one line with integer l(1<=l<=10000).
Output
For each test case, print one line, the shade area in the picture. The answer is round to two digit.
Sample Input
1
1
Sample Output

0.29

求阴影部分面积。

高数学得好的话可以用微积分。。。没错,我暂时还不会。。。

我还是拿出kuangbin模版,求出两个圆相交的面积S,然后用小圆的面积减去S就是一半的阴影部分,再乘以2就是结果。

#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define maxn 100005
#define maxm 100005
#define mod 1000000007
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const double eps=1e-18;
const double PI=acos(-1.0);
struct p{
    double x,y;
    p(){}
    p(double _x,double _y){x=_x;y=_y;}
    p operator -(const p &b)const{
        return p(x-b.x,y-b.y);
    }
    double operator *(const p &b)const{
        return x*b.x + y*b.y;
    }
};
double dist(p a,p b){
    return sqrt((a-b)*(a-b));
}
double A(p c1,double r1,p c2,double r2){
    double d=dist(c1,c2);
    if(r1+r2<d+eps)return 0;
    if(d<fabs(r1-r2)+eps){
        double r=min(r1,r2);
        return PI*r*r;
    }
    double x=(d*d+r1*r1-r2*r2)/(2.0*d);
    double t1=acos(x/r1);
    double t2=acos((d-x)/r2);
    return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        double  l;scanf("%lf",&l);
        p p1,p2;p1.x=0,p1.y=l;
        p2.x=l/2,p2.y=l/2;
        double ans=((PI*l/2*l/2)-A(p1,l,p2,l/2))*2.0;
        printf("%.2lf\n",ans);
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值