hdu---(Tell me the area)(几何/三角形面积以及圆面积的一些知识)
Tell me the area
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1876 Accepted Submission(s): 567
Problem Description
There are two circles in the plane (shown in the below picture), there is a common area between the two circles. The problem is easy that you just tell me the common area.
Input
There are many cases. In each case, there are two lines. Each line has three numbers: the coordinates (X and Y) of the centre of a circle, and the radius of the circle.
Output
For each case, you just print the common area which is rounded to three digits after the decimal point. For more details, just look at the sample.
Sample Input
0 0 2 2 2 1
Sample Output
0.108
Author
wangye
Source
2008 “Insigma International Cup” Zhejiang Collegiate Programming Contest - Warm Up(4)
对于平面内,任意两个圆,存在这些关系: 内含和内切,以及相交,外切和外离。
(1)对于内切,我们只需要求出面积最小圆的面积,
(2)对于外切及外离,得到的面积必然为0.0;
(3)对于相交,那么我们需要求出这些
: 知道两点坐标: 求出dist两点之间的距离;
知道三边,可以求出三边对应的角度: a^2+b^2-2*a*b*cos(g)=dist^2;
对于四边形的面积: sm=s3(三角形的面积)*2;
s3=sqrt(p*(p-r1)*(p-r2)*(p-d));
然后求出对应两个扇形的面积:s1,s2 依据: s=1/2*g*r*r;
最后: s=s1+s2-sm;
代码:
1 #include<cstdio>
2 #include<cmath>
3 #include<algorithm>
4 #include<iostream>
5 using namespace std;
6
7 struct circle
8 {
9 double x,y,r;
10 };
11 double dist(circle a,circle b)
12 {
13 return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
14 }
15 int main()
16 {
17 circle a,b;
18 double d,p,area,sb,sa;
19 while(scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&a.r,&b.x,&b.y,&b.r)!=EOF)
20 {
21 d=dist(a,b);
22 double rr=min(a.r,b.r);
23 if(d<=abs(a.r-b.r)) //内含或者内切
24 area=acos(-1.0)*rr*rr;
25 else
26 if(d>=a.r+b.r)
27 area=0.0;
28 else{
29 p=(a.r+b.r+d)/2.0;
30 sa=acos((a.r*a.r+d*d-b.r*b.r)/(2.0*a.r*d));
31 sb=acos((b.r*b.r+d*d-a.r*a.r)/(2.0*b.r*d));
32 area=sa*a.r*a.r+sb*b.r*b.r-2*sqrt(p*(p-a.r)*(p-b.r)*(p-d));
33 }
34 printf("%.3lfn",area);
35 }
36 return 0;
37 }
- Go并发编程基础(译)
- go-concurrent-programming.md
- Go语言并发模型:以并行处理MD5为例
- golang 使用json 包 实现序列化
- 【远古文章】用 Go 语言来看 Android! 出发, Android, 出发!
- Leaf 游戏服务器框架简介
- MongoDB 存储过程的使用以及性能调优方案
- [go语言]利用缓冲信道来实现网游帐号验证消息的分发和等待
- 【Golang语言社区--投稿专区】简单,好玩,有趣的命令行版12306(golang)
- 网游内存数据库的设计(1)
- 网游内存数据库的设计(2)
- Golang语言 上传文件
- Golang语言 监控文件变化小程序.
- Golang语言实现 tail 查看文本文件末行功能,类似于linux tail -n 100 功能
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法