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代码:
#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解题思路 Ural解题思路 Ural解题思路 Ural解题思路
Ural
URAL3D
Pascal acm_timus_ural_1148.pas
URAL(Timus Online Judge)部分测试数据 不全
Ural 1238 源代码 涉及算法(动态规划、贪心、DFS)
In particular, the development of cloud computing, logistics networks, big data, and quantum information has played an unprecedented role in promoting the globalization of machine learning. In modern...
Pascal acm_timus_ural_1099.pas
28. The Theoretical Background of the Ural-Altale Hypothesis The hypothesis of common origin of the Altaic languages,and even the Ural-Altaic languages,dates from the first half of the last century....
and the National Geographic Society[5] as 4/5 of the landmass of Eurasia – with the western portion of the latter occupied by Europe – located to the east of the Suez Canal, east of the Ural ...
包含了ural题库中Vol_I 到Vol_III的所有题目的解题思路
ural 题解 yuhch123。 关于yuhch123: ioi2008 金牌第一名,这是当初它做ural 第一卷时的题解
部分题解 大牛出品 Vol1-3 不是很全,约有200题左右
URAL-PHA
Crystal Structure of Solid Solutions and Phase Relations in the La-Co-Fe-O System Poster Crystal Structure of Solid Solutions and Phase Relations in the La-Co-Fe-O System N. V. Proskurnina, O. S. ...
Ural ACM 1000源代码(c++),vc++6.0在XPsp2下编译通过,Timus Online Judge再线测评通过
poj 2528 需要离散化,建树不同,需要处理不同->注意这组数据 3 1 10 1 3 6 10 the ans is 3. hdu 1754 求区间最大值 hdu 1166 求区间和 hdu 1698 成段更新 poj 3468 成段更新 ural 1019 覆盖加统计最长同一个颜色 ...
因为大三了 不弄ACM了 所以这些就删了 删之前希望可以帮到别人
资源分类:Python库 所属语言:Python 资源全名:ural-0.28.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
基于张量类模板的线性代数C ++库,可用于表示等级0的张量,标量向量,1的向量,2的矩阵,3的等级3的张量等。它还包括BLAS和LAPACK子例程的接口。