题意:给定两个圆环,求两个圆环的面积交。

析:很容易知道,圆环面积交就是,大圆与大圆面积交 - 大圆和小圆面积交 - 小圆和大圆面积交 + 小圆和小圆面积交。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 10 + 5;
const int mod = 1000;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r > 0 && r <= n && c > 0 && c <= m;
} int cmp(double x){
if(fabs(x) < eps) return 0;
return x > 0 ? 1 :-1;
}
struct Circle {
double x, y;
double r;
};
Circle big1, big2, small1, small2; double dis(const Circle &a, const Circle &b){
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
} double solve(const Circle &a, const Circle &b){
double d = dis(a,b);
if(d >= a.r + b.r) return 0;
if(d <= fabs(a.r - b.r)){
double r = a.r < b.r ? a.r : b.r;
return PI * r * r;
}
double ang1 = acos((a.r * a.r + d * d - b.r * b.r)/2. / a.r / d);
double ang2 = acos((b.r * b.r + d * d - a.r * a.r)/2. / b.r / d);
double ret = ang1 * a.r * a.r + ang2 * b.r * b.r - d * a.r * sin(ang1);
return ret;
} int main(){
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
scanf("%lf %lf", &small1.r, &big1.r);
small2.r = small1.r;
big2.r = big1.r;
scanf("%lf %lf", &small1.x, &small1.y);
scanf("%lf %lf", &small2.x, &small2.y);
big1.x = small1.x;
big1.y = small1.y;
big2.x = small2.x;
big2.y = small2.y;
double ans = solve(big1, big2) - solve(big1, small2) - solve(big2, small1) + solve(small1, small2);
printf("Case #%d: %.6f\n", kase, ans);
}
return 0;
}

  

HDU 5120 Intersection (圆的面积交)的更多相关文章

  1. hdu 5120 Intersection

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 A ring is a 2-D figure bounded by two circles sh ...

  2. hdu 5120 Intersection 两个圆的面积交

    Intersection Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) P ...

  3. poj3675 求多边形与圆的面积交

    题意:给出多边形的顶点坐标.圆的圆心坐标和半径,求面积交 sol:又是模板题啦= = 注意poj的C++好像认不出hypot函数,要稍微改写一下. hypot(double x,double y):即 ...

  4. 覆盖的面积 HDU - 1255(扫描线求面积交)

    题意: 就是扫描线求面积交 解析: 参考求面积并.... 就是把down的判断条件改了一下..由w > 0 改为 w > 1 同时要讨论一下 == 1 时  的情况, 所以就要用到一个临时 ...

  5. hdu 5120 Intersection 圆环面积交

    Intersection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...

  6. 计算几何(容斥原理,圆交):HDU 5120 Intersection

    Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...

  7. hdu 5120 Intersection (圆环面积相交->圆面积相交)

    Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made up by ...

  8. HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...

  9. POJ 3675 Telescope 简单多边形和圆的面积交

    这道题得控制好精度,不然会贡献WA  QAQ 还是那个规则: int sgn(double x){ if(x > eps) return 1; else if(x < - eps) ret ...

随机推荐

  1. 全面剖析Smarty缓存机制一[三种缓存方式]

    今天主要全面总结下Smarty模板引擎中强大的缓存机制,缓存机制有效减少了系统对服务器的压力,而这也是很多开发者喜欢Smarty的原因之一,由于篇幅较大,便于博友阅读,这篇文章将剖析Smarty缓存的 ...

  2. 性能测试-Loadrunner组件Controller一

    Loadrunner应用之Controller Loadrunner工具,通常看到的有三大核心组件,VuGen.Controller.Analysis,今天我们继续来聊一下,其中的一个核心组件:Con ...

  3. Spring AOP 实现读写分离

    原文地址:Spring AOP 实现读写分离 博客地址:http://www.extlight.com 一.前言 上一篇<MySQL 实现主从复制> 文章中介绍了 MySQL 主从复制的搭 ...

  4. OneProxy常用参数说明

    5.2.OneProxy常用参数说明 OneProxy的所有可用参数可通过oneproxy --help-all查看.所有参数均可以写入文件中,由OneProxy启动时加载 5.2.1.基本参数 -- ...

  5. 黄聪:中国大陆的所有IP段,中国电信所有IP段、中国铁通所有IP段、中国网通所有IP段。

    中国大陆的所有IP段,中国电信所有IP段.中国铁通所有IP段.中国网通所有IP段. 中国大陆的所有IP段: 47.153.128.0 47.154.255.25558.14.0.0 58.25.255 ...

  6. while循环-for循环

    while true: 无限循环语句 break跳出循环,当count=1000的时候结束循环 count是结束当前循环'''count = 0while True: print("coun ...

  7. 停止调试 IIS 不退出

    在VS主面板打开:工具->选项->调试->编辑继续   取消选中[启用"编辑并继续"] 就可以(不过这是针对所有的调试). 若只想对单个项目进行设置,可以选择自己 ...

  8. android中一个评分的控件

    RatingBar android中一个评分的控件 如何使用 Android Studio下: dependencies { compile 'com.hedgehog.ratingbar:app:1 ...

  9. 第10课 初探 Qt 中的消息处理

    1. Qt消息模型 (1)Qt封装了具体操作系统的消息机制 (2)Qt遵循经典的GUI消息驱动事件模型 2. 信号与槽 (1)Qt中定义了与系统消息相关的概念 ①信号(Signal):由操作系统产生的 ...

  10. 《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #11cpuset

    HACK #11cpuset 本节介绍控制物理CPU分配的cpuset.cpuset是Linux控制组(Cgroup)之一,其功能是指定特定进程或线程所使用的CPU组.另外,除CPU以外,同样还能指定 ...