URAL Goat in the Garden(圆与矩形求交集面积)
2014-09-17 21:03
459 查看
URAL Goat in the Garden(圆与矩形求交集面积)
http://acm.timus.ru/problem.aspx?space=1&num=1084
题意:
一些人让一只山羊到一个方形的草地上并且把它绑在了一个棒子上。这个棒子被钉在了这个正方形的正中间。山羊很饿很贪婪,把所有它能够到的在正方形里的草都吃了。草地的哪个区域会被吃掉?
分析:
根据绳子的长R和正方形边长的一半h,可以分为下面三种情况:
R<=h时, 所求为圆面积 R^2*π.
R*R>=2*h*h时(其实就是R>=正方形对角线长时),所求为正方形面积4*R*R.
R>h且R*R<2*h*h时,所求为圆形面积减去 4个弓形的面积,如下图所示:
其中弓形面积= 扇形面积-三角形面积.
AC代码:
http://acm.timus.ru/problem.aspx?space=1&num=1084
题意:
一些人让一只山羊到一个方形的草地上并且把它绑在了一个棒子上。这个棒子被钉在了这个正方形的正中间。山羊很饿很贪婪,把所有它能够到的在正方形里的草都吃了。草地的哪个区域会被吃掉?
分析:
根据绳子的长R和正方形边长的一半h,可以分为下面三种情况:
R<=h时, 所求为圆面积 R^2*π.
R*R>=2*h*h时(其实就是R>=正方形对角线长时),所求为正方形面积4*R*R.
R>h且R*R<2*h*h时,所求为圆形面积减去 4个弓形的面积,如下图所示:
其中弓形面积= 扇形面积-三角形面积.
AC代码:
#include<cstdio> #include<cmath> using namespace std; const double PI=acos(-1.0); double r,h; int main() { while(scanf("%lf%lf",&h,&r)==2) { h/=2; double ans=0; if(h>=r) ans=PI*r*r;//矩形包围圆 else if(r*r>=2*h*h) ans=4*h*h;//圆包围矩形 else//圆与矩形相交 { double area=acos(h/r)*r*r-h*sqrt(r*r-h*h);//弓形面积 ans = PI*r*r-4*area; } printf("%.3lf\n",ans); } return 0; }
相关文章推荐
- URAL 1084 || Goat in the Garden(同中心矩形与圆的公共面积
- ural 1348 Goat in the Garden 2
- 【点到线段距离】URAL - 1348 Goat in the Garden 2
- ural 1084 Goat in the Garden
- URAL 1348 Goat in the Garden 2计算几何(解题报告)
- Goat in the Garden (ural 1348)
- URAL 1348 Goat in the Garden 2(点到线段的距离)
- ural 1084 Goat in the Garden
- URAL 1348 Goat in the Garden 2(点到线段的距离)
- URAL 1348 Goat in the Garden 2(点到线段的距离)
- ural 1348. Goat in the Garden 2
- Ural1084. Goat in the Garden
- Ural 1084|Goat in the Gardon|计算几何
- sgu 1348 Goat in the Garden 2【点到线段的距离】
- Ural_1348. Goat in the Garden 2(计算几何)
- Goat in the Garden 2&&http://acm.timus.ru/problem.aspx?space=1&num=1348
- Ural-1084. Goat in the Garden(计算几何)
- ural 1084. Goat in the Garden
- URAL 1348. Goat in the Garden 2[求点到线段的距离]
- GYM 100488 A. Yet Another Goat in the Garden(计算几何)