hdu 1798
来源:互联网 发布:淘宝卖家手机打印快递 编辑:程序博客网 时间:2024/05/18 01:12
Tell me the area
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1382 Accepted Submission(s): 430
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 22 2 1
Sample Output
0.108
Author
wangye
Source
2008 “Insigma International Cup” Zhejiang Collegiate Programming Contest - Warm Up(4)
Recommend
wangye
//分三种情况考虑两个圆关系:1.两圆相离、外切或至少有一圆半径为0; // 2.两圆内切、内含;// 3.相交。//这里PI用acos(-1.0),用3.1415926的话会WA.#include <stdio.h>#include <math.h>#define PI acos(-1.0)int main(){double x1, y1, r1, x2, y2, r2, dis, s, angle1, angle2, s1, s2, s3, s4;while (~scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &r1, &x2, &y2, &r2)){dis = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));if(dis >= r1 + r2 || r1 == 0 || r2 == 0)s = 0;else if(dis <= fabs(r1 - r2)){r1 = r1 > r2 ? r2 : r1;s = PI * r1 * r1;}else{angle1 = acos((r1 * r1 + dis * dis - r2 * r2) / (2 * r1 * dis));angle2 = acos((r2 * r2 + dis * dis - r1 * r1) / (2 * r2 * dis));s1 = angle1 * r1 * r1;s2 = r1 * r1 * sin(angle1) * cos(angle1);s3 = angle2 * r2 * r2;s4 = r2 * r2 * sin(angle2) * cos(angle2);s = s1 - s2 + s3 - s4;}printf("%.3lf\n", s);}return 0;}
- hdu 1798
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- Qwt源码解读之缩放操作类
- jquery表单验证插件的使用
- Meteor.js
- Cocos2d-x开关按钮CCMenuItemToggle的使用
- Visual C++ 2012入门经典(第6版)
- hdu 1798
- Jquery异步提交返回json结果问题
- 格式化SQL语句的网站
- 清除DEV控件 CodeRush的缓存
- 管理可恢复空间
- 如何判断 double/float 变量是否有效 (#IND, #INF)
- UXEDO配置参数详解 远程客户端配置
- GDI+ PNG背景透明窗口 初始化调用一次 必须有layer属性,image*注意赋值
- UL LI结构实现二级导航菜单(HTML+CSS+JS)