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

Hard problem

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


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
 

Recommend
wange2014
 

思路:

先求出半径为d的大圆与半径为d/2的小圆相交的面积,用小圆的面积减去相交的面积是一块阴影部分的面积,最后乘以2即可。

还可以做几条辅助线求出一些角度,直接计算。

代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.0);
struct Point
{
    double x,y;
    Point(){};
    Point(double _x,double _y)
    {
        x=_x; y=_y;
    }
    Point operator -(const Point &b)const
    {
        return Point(x-b.x,y-b.y);
    }
    double operator *(const Point &b)const
    {
        return x*b.x+y*b.y;
    }
    void transXY(double B)
    {
        double tx = x,ty=y;
        x=tx*cos(B)-ty*sin(B);
        y=tx*sin(B)+ty*cos(B);
    }
};
double dist(Point a,Point b)
{
    return sqrt((a-b)*(a-b));
}
double Area_of_overlap(Point c1,double r1,Point 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*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 d;
        scanf("%lf",&d);
        Point a = Point(0,0);
        Point b = Point(d/2,d/2);
        printf("%.2f\n",2*(PI*d*d/4-Area_of_overlap(a,d,b,d/2)));
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值