2016多校训练Contest10: 1002 Hard problem hdu5858

本文介绍了一道针对小学生的奥林匹克数学题目,该题目要求计算特定几何图形中阴影部分的面积。通过给出的边长信息,利用编程方法精确计算出答案,并提供了样例输入输出以验证解决方案的有效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

似乎是从中间切开两边用积分求一下。。具体的我不太会推

另外还可以用各种软件直接弄出来

#include <stdio.h>
#include <math.h>
struct point{
    double x,y;
};
double distance(point p1,point p2){
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double area_of_overlap(point c1, double r1, point c2, double r2){
    double a = distance(c1, c2), b = r1, c = r2;
    double cta1 = acos((a * a + b * b - c * c) / 2 / (a * b)),
           cta2 = acos((a * a + c * c - b * b) / 2 / (a * c));
    double s1 = r1*r1*cta1 - r1*r1*sin(cta1)*(a * a + b * b - c * c) / 2 / (a * b);
    double s2 = r2*r2*cta2 - r2*r2*sin(cta2)*(a * a + c * c - b * b) / 2 / (a * c);
    return s1+s2;
}
int main(void){
    int t;
    int n;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        point a,b;
        a.x = 0.5*n;
        a.y = 0.5*n;
        b.x = 0;
        b.y = 0;
        double ans = area_of_overlap(a,0.5*n,b,n);
        printf("%.2f\n",2*(0.5*n*0.5*n*acos(-1) - ans));
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值