HDU 5858 Hard problem(求角度的模板)

来源:互联网 发布:vivo软件版本号 编辑:程序博客网 时间:2024/05/10 06:55

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)

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

题意: 给你这个图,和正方形的边长,让你求出这个图中的阴影部分面积,圆的中间部分的阴影面积不算。

思路: 这道题,其实是个数学题,网上还有解法,然而我并不知道,嗯,就是这样,所以上图······

这里写图片描述

注意: 有了解法之后,其实跟着步奏来就不难了,然而问题是我并没有用过C语言来求角度啊,面积啊啥的,所以我还是一脸懵逼,然而问了同学之后,其实还是挺简单的。

#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<vector>#include<string>#include<queue>#include<map>#include<stack>#include<set>#define ll long long#define maxn 1000010#define PI acos(-1.0)    //圆周率//#define PI 3.14const int mod=1e4+7;using namespace std;int T;double a;int main(){    double a=1.0;    double b=a/2.0;    double c=a;    double d=sqrt(2)*a/2.0;    double p=(b+c+d)/2;    double SA=sqrt(p*(p-b)*(p-c)*(p-d));   //根据海伦定理来求三角形面积    double hanja=(c*c+d*d-b*b)/(2*c*d);   //根据余弦定理来求出角度的cos值    double ja=acos(hanja);   //这个函数相当于arccos(反余弦),就是求这个的角度,因为要求扇形的面积,所以要用到角度    double shanjia=ja*c*c/2.0;    //别忘了这里要除以2.0,当时算来算去算不对就是因为少了这个2.0    double hanjb=(b*b+d*d-c*c)/(2*b*d);    double jb=PI-acos(hanjb);   //求角的补角,就是直接用圆周率减去他就行了,或者只是在括号里面加个负号,效果是一样的    double shanjib=jb*(b*b)/2.0;    double ans=shanjib-(shanjia-SA);    scanf("%d",&T);    while(T--)    {        double l;        scanf("%lf",&l);        double answer=ans*l*l*4;   //因为面积是相似的,所以直接就是先处理当正方形边长是1的时候的情况,然后再求乘于正方形的面积就行了        printf("%.2lf\n",answer);    }    return 0;}
0 0