HDU 5858 Hard problem【两圆的面积交】

Hard problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 643    Accepted Submission(s): 410


Problem Description
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
 

Author
BUPT
 

Source
 
      思路:可以先求出最上面黑色区域的面积,那块面积可以看作中间的圆的面积减去和下面的那个1/4圆的交面积。

就变成了求两个圆面积交问题了。


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define ll long long
#define ms(a,b)  memset(a,b,sizeof(a))
const int M=1e6+10;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
int i,j,k,n,m;

#define pi acos(-1.0)

typedef struct node
{
    double x;
    double y;
}point;

double AREA(point a, double r1, point b, double r2)
{
    double d=sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
    if(d>=r1+r2)return 0;
    if(r1>r2){
        double tmp=r1;
        r1=r2;
        r2=tmp;
    }
    if(r2-r1>=d)
        return pi*r1*r1;
    double ang1=acos((r1*r1+d*d-r2*r2)/(2*r1*d));
    double ang2=acos((r2*r2+d*d-r1*r1)/(2*r2*d));
    return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
       double kk;
       scanf("%lf",&kk);
       point a, b;
       a.x=kk/2.0, a.y=kk/2.0;
       b.x=kk, b.y=0;
       double r1=kk/2.0;
       double r2=kk;
       double res= AREA(a, r1, b, r2);
       double ans=(pi*(kk/2.0)*(kk/2.0)-res)*2.0;
       printf("%.2f\n",ans);
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值