hdu5858 Hard problem(求两圆相交面积)
题目传送门
Hard problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1066 Accepted Submission(s): 622
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.
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
题意:求阴影部分面积
题解:求圆与圆相交面积的模板
代码:
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> PII;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
//head
const double PI=acos(-1);
struct Round{
double x,y;
double r;
}c1,c2;
double dis(Round a,Round b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double solve(Round a,Round b)
{
double d=dis(a,b);
double ang1=acos((a.r*a.r+d*d-b.r*b.r)/2/a.r/d);
double ang2=acos((b.r*b.r+d*d-a.r*a.r)/2/b.r/d);
double ret=ang1*a.r*a.r+ang2*b.r*b.r-d*a.r*sin(ang1);
return ret;
}
int main()
{
c1.x=0.5,c1.y=0.5,c1.r=0.5;
c2.x=0,c2.y=0,c2.r=1;
double sum=solve(c1,c2);
sum=PI*0.5*0.5-sum;
sum=sum*2;
int T;
scanf("%d",&T);
int L;
while(T--)
{
scanf("%d",&L);
printf("%.2f\n",sum*L*L);
}
return 0;
下面是两圆求相交面积的模板
const double PI = acos(-1); struct Round { double x, y; double r; }c1,c2; double dis(Round a, Round b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double solve(Round a, Round b) { double d = dis(a, b); if (d >= a.r + b.r) return 0; if (d <= fabs(a.r - b.r)) { double r = a.r < b.r ? a.r : b.r; return PI * r * r; } double ang1 = acos((a.r * a.r + d * d - b.r * b.r) / 2. / a.r / d); double ang2 = acos((b.r * b.r + d * d - a.r * a.r) / 2. / b.r / d); double ret = ang1 * a.r * a.r + ang2 * b.r * b.r - d * a.r * sin(ang1); return ret; }