Tell me the area---hdu1798 (数学 几何)
2024-08-30 16:35:26
http://acm.hdu.edu.cn/showproblem.php?pid=1798
给你两个圆求阴影部分的面积
求出两个扇形的面积减去四边形的面积
扇形的面积是度数(弧度制)*半径的平方
不能用PI 3.1415926 要用acos(-1.0);
求四边形面积就是两个三角形 用海伦公式
因为精确度比较高 所以就不能用PI 3.1415926
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <math.h> using namespace std;
#define memset(a,b) memset(a,b,sizeof(a))
#define N 1100000
typedef long long ll;
#define PI 3.1415926 int main()
{
double x1,y1,r1,x2,y2,r2;
while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&r1,&x2,&y2,&r2)!=EOF)
{
double rr=min(r1,r2);
double l=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
if(l>=r1+r2)
{
printf("0.000\n");
continue;
}
else if(l<=fabs(r1-r2))
{ printf("%.3lf\n",acos(-1.0)*rr*rr);
continue;
}
double cos1=(r1*r1+l*l-r2*r2)/(2.0*r1*l);
double cos2=(r2*r2+l*l-r1*r1)/(2.0*r2*l); double ss1=r1*acos(cos1)*r1;///r1扇形的面积
double ss2=r2*acos(cos2)*r2;
double p=(r1+r2+l)/2.0;///
double S=*sqrt(p*(p-r1)*(p-r2)*(p-l));///四边形的面积
printf("%.3lf\n",ss1+ss2-S);
}
return ;
}
最新文章
- js url.slice(star,end) url.lastIndexOf(&#39;/&#39;) + 1, -4
- 深入理解javascript系列,读书笔记
- Oracle添加数据报文字与格式字符串不匹配错误
- jboss服务器修改端口说明
- 实验 snort安装配置与规则编写
- 基于.NET的WebService的实现和WCF的实现
- Spark生态系统BDAS
- JQuery Ajax 在asp.net中使用小结
- PHP reset() 函数
- javascript 倒计时代码
- jquery ajax 跨域提交(附IE浏览器解决方案)
- String的使用
- [Go语言学习]之一:搭建单元测试环境
- (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数&;lt;=3,输出剩下的人 )
- MIPS(极路由1s[mt7620a])平台OpenWrt路由器系统内的Go应用程序开发
- 【Java】【13】两个double类型比较大小
- Largest Rectangle in a Histogram POJ - 2559 (单调栈)
- 3.2 unittest执行顺序
- stm32的双向io口
- Java List <;T>; T[] toArray(T[] a) implementation