ural 1084. Goat in the Garden
2011-05-09 17:46
459 查看
水题啦。。给你一个正方形区域,中间有个柱子栓了一只山羊,给出方形的边长和山羊绳子的长度,求山羊不超过方形所能吃到草的面积。
三种情况,绳子长 < 边长一半(求圆形面积即可)。 绳子 > 边长一半 && 绳子 < 根号2*边长一半(圆形减去4个弓形面积)。 绳子 大于根号2*边长一半(求方形面积)。
用了两种方法求解。。。没测出来哪个精度高。。。都A了。。
三种情况,绳子长 < 边长一半(求圆形面积即可)。 绳子 > 边长一半 && 绳子 < 根号2*边长一半(圆形减去4个弓形面积)。 绳子 大于根号2*边长一半(求方形面积)。
用了两种方法求解。。。没测出来哪个精度高。。。都A了。。
#include <queue> #include <stack> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <string.h> #include <algorithm> using namespace std; const double pi = acos(-1.0); double d,r; double area_gong() { double area = sqrt(r*r - d*d/4)*d/2; double b = asin(area*2/(r*r)); return r*r*b/2 - area; } int main() { scanf("%lf %lf",&d,&r); if( 2*r <= d ) printf("%.3lf/n",pi*r*r); else if( r >= d/sqrt(2.0) ) printf("%.3lf/n",d*d); else { double area = area_gong(); printf("%.3lf/n",pi*r*r - 4*area); } return 0; }
#include <queue> #include <stack> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <string.h> #include <algorithm> using namespace std; const double pi = acos(-1.0); double d,r; double area_gong() { double a = 2*acos(d/(2*r)); return r*r*a/2 - r*r*sin(a)/2; } int main() { scanf("%lf %lf",&d,&r); if( 2*r <= d ) printf("%.3lf/n",pi*r*r); else if( r >= d/sqrt(2.0) ) printf("%.3lf/n",d*d); else { double area = area_gong(); printf("%.3lf/n",pi*r*r - 4*area); } return 0; }
相关文章推荐
- Ural1084. Goat in the Garden
- 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
- URAL 1348 Goat in the Garden 2(点到线段的距离)
- ural 1348 Goat in the Garden 2
- Ural_1348. Goat in the Garden 2(计算几何)
- URAL 1348 Goat in the Garden 2(点到线段的距离)
- Goat in the Garden (ural 1348)
- URAL 1348 Goat in the Garden 2(点到线段的距离)
- URAL Goat in the Garden(圆与矩形求交集面积)
- ural 1084 Goat in the Garden
- ural 1084 Goat in the Garden
- URAL 1348. Goat in the Garden 2[求点到线段的距离]
- URAL 1145—— Rope in the Labyrinth——————【求树的直径】
- URAL 1949 The Best Picture in the Galaxy 二分匹配 求字典序最小解
- URAL 1145. Rope in the Labyrinth(两次BFS啊 )
- ural 1101(Robot in the Field )表达式求值