poj 2546 Circular Area

Description

Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point.

Input

In the single line of input file there are space-separated real numbers x1 y1 r1 x2 y2 r2. They represent center coordinates and radii of two circles.

Output

The output file must contain single real number - the area.

Sample Input

20.0 30.0 15.0 40.0 30.0 30.0

Sample Output

608.366

求两园相交面积
 1 #include <iostream>
 2 #include <math.h>
 3 #include <stdio.h>
 4 using namespace std;
 5 double dis(double x1, double y1, double x2, double y2) {
 6     return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
 7 }
 8 int main() {
 9     double pi = acos(-1);
10     double gx, gy, gr, wx, wy, wr;
11     while(scanf("%lf %lf %lf %lf %lf %lf", &gx, &gy, &gr, &wx, &wy, &wr) != EOF) {
12         double dd = dis(gx, gy, wx, wy);
13         if(dd >= (wr + gr) || wr == 0 || gr == 0) printf("0.000\n");
14         else if(dd <= fabs(wr - gr)) {
15             double rr = min(wr, gr);
16             printf("%.3f\n",rr*rr*pi);
17         } else {
18             double a1 = acos((gr*gr + dd*dd - wr*wr) / (2*gr*dd));
19             double a2 = acos((wr*wr + dd*dd - gr*gr) / (2*wr*dd));
20             double area1 = (sin(a1*2)*gr*gr+sin(a2*2)*wr*wr)/2;
21             double area2 = gr*gr*a1 + wr*wr*a2;
22             printf("%.3f\n",(area2-area1));
23         }
24     }
25     return 0;
26 }
时间: 2024-08-03 03:28:25

poj 2546 Circular Area的相关文章

poj 2546 Circular Area 两圆面积交

题意: 给两个圆,求它们的面积交. 分析: 海伦公式,余弦定理等可解. 代码: //poj 2546 //sep9 #include <iostream> #include <cmath> using namespace std; const double pi=acos(-1.0); int main() { double x1,y1,r1,x2,y2,r2; scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1

poj 2546 Circular Area (两圆相交面积)

链接:poj 2546 题意:已知两圆的圆心和半径,求两圆相交部分的面积 分析:两圆的位置关系有三种:相离,相交,内含 相离时:相交面积为0 相交时,大扇形面积+小扇形面积-四边形面积 内含时,相交面积为小圆面积 #include<stdio.h> #include<math.h> #define PI acos(-1.0) typedef struct stu { double x,y; }point; double Distance(point a,point b) { ret

POJ 2546 Circular Area(两个圆相交的面积)

题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆心坐标(x2,y2). d为两圆圆心连线的长度. 相交面积为S d=sqrt((x1-x2)^2+(y1-y2)^2) (1)如果r1+r2<=d 那么两圆相离,相交面积S=0 (2)如果r2-r1>=d 那么半径小的圆内含半径大的圆,那么相交面积为小圆的面积S=pi*r1*r1 (3)既非(1)

POJ 2546 &amp; ZOJ 1597 Circular Area 两圆的面积交

Circular Area Time Limit: 2 Seconds      Memory Limit: 65536 KB Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point. Input In the single line of in

poj 2546(两圆公共面积)

Circular Area Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5682   Accepted: 2225 Description Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after

POJ 1265:Area

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4725   Accepted: 2135 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

POJ 2546 &amp; ZOJ 1597 Circular Area(求两圆相交的面积 模板)

题目链接: POJ:http://poj.org/problem?id=2546 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=597 Description Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three di

poj 3940 Grey Area 浮点输出控制

水题,直接贴代码,注意几种控制浮点输出的方法:e格式,以指数形式输出实数.g格式:自动选f格式或e格式中较短的一种输出,且不输出无意义的零. 代码: //poj 3940 //sep9 #include <iostream> using namespace std; const int maxL=64; int cnt[maxL+10]; double color[maxL]; double area[maxL]; int main() { double p=0.10000; int n,w;

POJ题目1265 Area(PICK定理)

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5248   Accepted: 2352 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear