题目链接:

POJ:http://poj.org/problem?

id=2546

ZOJ:

problemId=597" target="_blank">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 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

Source

Northeastern Europe 2000, Far-Eastern Subregion

题意:

求两圆相交的面积!

直接上模板

代码例如以下:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
//#include <complex>
//#include <iomanip>
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.0); int sgn(double x)
{
if(fabs(x) < eps) return 0;
if(x < 0) return - 1;
else return 1;
}
struct Point
{
double x, y;
Point(){}
Point(double _x, double _y)
{
x = _x; y = _y;
}
Point operator -( const Point &b) const
{
return Point(x - b. x, y - b. y);
}
//叉积
double operator ^ (const Point &b) const
{
return x*b. y - y*b. x;
}
//点积
double operator * (const Point &b) const
{
return x*b. x + y*b. y;
}
//绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B)
{
double tx = x,ty = y;
x = tx* cos(B) - ty*sin(B);
y = tx* sin(B) + ty*cos(B);
}
};
//*两点间距离
double dist( Point a, Point b)
{
return sqrt((a-b)*(a- b));
}
//两个圆的公共部分面积
double Area_of_overlap(Point c1, double r1, Point c2, double r2)
{
double d = dist(c1,c2);
if(r1 + r2 < d + eps) return 0;
if(d < fabs(r1 - r2) + eps)
{
double r = min(r1,r2);
return PI*r*r;
}
double x = (d*d + r1*r1 - r2*r2)/(2*d);
double t1 = acos(x / r1);
double t2 = acos((d - x)/r2);
return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
} int main()
{
double x1, y1, r1, x2, y2, r2;
while(~scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&r1,&x2,&y2,&r2))
{
Point c1, c2;
c1.x = x1;
c1.y = y1;
c2.x = x2;
c2.y = y2;
double ans = Area_of_overlap(c1,r1,c2,r2);
printf("%.3lf\n",ans);
//cout<<setiosflags(ios::fixed)<<setprecision(3)<<ans<<endl;
}
return 0;
}

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

  1. 求两圆相交部分面积(C++)

    已知两圆圆心坐标和半径,求相交部分面积: #include <iostream> using namespace std; #include<cmath> #include&l ...

  2. hdu 5120 (求两圆相交的面积

    题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...

  3. hdu5858 Hard problem(求两圆相交面积)

    题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  4. poj2546Circular Area(两圆相交面积)

    链接 画图推公式 这两种情况 都可用一种公式算出来 就是两圆都求出圆心角 求出扇形的面积减掉三角形面积 #include <iostream> using namespace std; # ...

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

    题目链接 题意 : 给你两个圆的半径和圆心,让你求两个圆相交的面积大小. 思路 : 分三种情况讨论 假设半径小的圆为c1,半径大的圆为c2. c1的半径r1,圆心坐标(x1,y1).c2的半径r2,圆 ...

  6. 两圆相交求面积 hdu5120

    转载 两圆相交分如下集中情况:相离.相切.相交.包含. 设两圆圆心分别是O1和O2,半径分别是r1和r2,设d为两圆心距离.又因为两圆有大有小,我们设较小的圆是O1. 相离相切的面积为零,代码如下: ...

  7. [poj] 1269 [zoj] 1280 Interesting Lines || 求两直线交点

    POJ原题 ZOJ原题 多组数据.每次给出四个点,前两个点确定一条直线,后两个点确定一条直线,若平行则输出"NONE",重合输出"LINE",相交输出" ...

  8. ZOJ 1280 Interesting Lines | 求两直线交点

    原题: 求两直线交点 思路借鉴于:http://blog.csdn.net/zxy_snow/article/details/6341282 感谢大佬 #include<cstdio> # ...

  9. UVa 10674 (求两圆公切线) Tangents

    题意: 给出两个圆的圆心坐标和半径,求这两个圆的公切线切点的坐标及对应线段长度.若两圆重合,有无数条公切线则输出-1. 输出是按照一定顺序输出的. 分析: 首先情况比较多,要一一判断,不要漏掉. 如果 ...

随机推荐

  1. 仿QQ聊天图文混排流程图【适用于XMPP】

      图文混排流程图.graffle4.8 KB   下面附上图片素材: 表情.zip692.5 KB     下面是字符串与图片的详细对应关系:                 "[呲牙]& ...

  2. shell脚本常用参数

    shell 脚本 常用参数 #!/bin/sh # 在脚本第一行脚本头 # sh为当前系统默认shell,可指定为bash等shell sh -x # 执行过程 sh -n # 检查语法 (a=bbk ...

  3. shiro登录成功之后跳转原路径

    通过 WebUtils.getSavedRequest(request) 来获取shiro保存在session登录之前的url 1:java Controller代码 @PostMapping(&qu ...

  4. python学习之——import sys模块

    (1)sys.argv sys模块中的argv变量通过使用点号指明——sys.argv——这种方法的一个优势是这个名称不会与任何在你的程序中使用的argv变量冲突.另外,它也清晰地表明了这个名称是sy ...

  5. j2ee组件简介

  6. gcc __attribute__关键字举例之visibility【转】

    转自:https://blog.csdn.net/starstarstone/article/details/7493144?utm_source=tuicool&utm_medium=ref ...

  7. git学习——Git 基础要点【转】

    转自:http://blog.csdn.net/zeroboundary/article/details/10549555 简单地说,Git 究竟是怎样的一个系统呢?请注意,接下来的内容非常重要,若是 ...

  8. springcloud微服务架构搭建:服务调用

    spring-cloud调用服务有两种方式,一种是Ribbon+RestTemplate, 另外一种是Feign. Ribbon是一个基于HTTP和TCP客户端的负载均衡器,类似nginx反向代理,可 ...

  9. jenkins之参数化构建

    事件背景: 今天一早接到一个需求,说要jenkins持续集成,输入自定义URL,然后完成回归测试,当时有点蒙,不知道如何下手,听群里的大神思路后豁然开朗,就记录了下 一.先安装插件 插件: [Buil ...

  10. 转:vue2.0 keep-alive最佳实践

    转载至:https://segmentfault.com/a/1190000008123035 1.基本用法 vue2.0提供了一个keep-alive组件用来缓存组件,避免多次加载相应的组件,减少性 ...