Grass Land

Problem D Grass Land

Description

Farmer John has a grass land, which is very large that when you standin the middle of it, you can not see its edge.

Farmer John had built his barn in the center of the grass land, which is rectangle shape ofw × h.And now in the barnlives his favourate cow Bessie.

One day, farmerJohn goes to the market and ties Bessie to one corner ofthe barn with a rope of length r. Therefore Bessiecan wander around the grass land as long as the rope allows her reach that point, meanwhile the rope may not pass through the barn.

Input

The first line contains a number T for the number of test cases. Then T cases follows. For each case there are three real numbers w, h, r (0 < w, h, r 1000) on one line.

Output

Output one real number on one line for each test case, the total area ofgrassland that Bessie canreach. You may assume that grass land is large enough that Bessie will not get out of the grass land. Round andkeep three digitalsafter the decimal point.

Example

SampleInput

SampleOutput

4

2 3 2

2 3 3

2 3 5

2 3 6

9.425

21.991

69.115

103.540

这是一道简单的构图题目,求牛能走过的最大面积,首先我们都知道牛能走过的最大面积一定是圆。

分情况讨论:

当r>=h&&r>=w时,sum=0.75*r*r*pi;

当r>=h&&r<=w时,sum=pi*r*r*0.75+0.25*pi*(w-r)*(w-r);

当r>=w&&r<=h时,sum=pi*r*r*0.75+0.25*pi*(w-h)*(w-h);

当r<=h&&r<=w&&r<=w+h sum=pi*r*r*0.75+0.25*(w-h)*(w-h)*pi+0.25*(w-r)*(w-r)*pi;

最后一种情况是r>w+h 需要做辅助线,分别连接两个圆心到焦点构成一个三角形,根据三角形求出各个角。

代码:

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
const double pi=atan(1.0)*4;
int main()
{
double q1,q2,q3,q4,w,h,r,sum,a,b,c,s;
int t;
cin>>t;
while(t--)
{
sum=0;
cin>>w>>h>>r;
if(h<=r&&r<=w) sum=0.75*pi*r*r+0.25*pi*(r-h)*(r-h);
else if(h>=r&&w<=r) sum=0.75*pi*r*r+0.25*pi*(r-w)*(r-w);
else if(w>=r&&h>=r) sum=0.75*pi*r*r;
else if(w<=r&&h<=r&&w+h>=r) sum=0.75*pi*r*r+0.25*pi*(r-h)*(r-h)+0.25*pi*(r-w)*(r-w);
else if(w<=r&&h<=r&&w+h<r)
{
a=sqrt(h*h+w*w);
b=r-h;
c=r-w;
s=(a+b+c)/2;
q1=atan(w/h);q3=atan(h/w);
q2=acos((a*a+b*b-c*c)/(2*a*b));
q4=acos((a*a+c*c-b*b)/(2*a*c));
//cout<<q1*360/2/pi<<' '<<q2*360/2/pi<<' '<<q3*360/pi/2<<' '<<q4*360/2/pi<<endl;
//cout<<q1*360/2/pi+q3*360/pi/2<<endl;
sum=0.75*pi*r*r+(pi-q1-q2)*(r-h)*(r-h)/2+(pi-q3-q4)*(r-w)*(r-w)/2+sqrt(s*(s-a)*(s-b)*(s-c))-0.5*w*h;
}
cout<<fixed<<setprecision(3)<<double(sum)<<endl;
}
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值