hdu 5120 Intersection 圆环面积交
Intersection
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5120
Description
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures are some famous examples you may know.
A ring is a 2-D figure bounded by two circles sharing the common center. The radius for these circles are denoted by r and R (r < R). For more details, refer to the gray part in the illustration below.
Matt just designed a new logo consisting of two rings with the same size in the 2-D plane. For his interests, Matt would like to know the area of the intersection of these two rings.
Input
The first line contains only one integer T (T ≤ 105), which indicates the number of test cases. For each test case, the first line contains two integers r, R (0 ≤ r < R ≤ 10).
Each of the following two lines contains two integers xi, yi (0 ≤ xi, yi ≤ 20) indicating the coordinates of the center of each ring.
Output
For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the area of intersection rounded to 6 decimal places.
Sample Input
2
2 3
0 0
0 0
2 3
0 0
5 0
Sample Output
Case #1: 15.707963
Case #2: 2.250778
HINT
题意
给你两个一样的圆环,问你这两个圆环相交的面积是多少
题解:
容斥定理就好了,剩下的都是套版
面积=大交大-大交小+小交小
代码:
//qscqesze
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000006
#define mod 1001
#define eps 1e-9
#define PI acos(-1)
const double EP = 1E- ;
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//*************************************************************************************
struct Circle{
double x,y;
double r;
}; double calArea(Circle c1, Circle c2)
{
double d;
double s,s1,s2,s3,angle1,angle2,temp; d=sqrt((c1.x-c2.x)*(c1.x-c2.x)+(c1.y-c2.y)*(c1.y-c2.y));
if(d>=(c1.r+c2.r))//两圆相离
return ;
if((c1.r-c2.r)>=d)//两圆内含,c1大
return acos(-1.0)*c2.r*c2.r;
if((c2.r-c1.r)>=d)//两圆内含,c2大
return acos(-1.0)*c1.r*c1.r; angle1=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(*c1.r*d));
angle2=acos((c2.r*c2.r+d*d-c1.r*c1.r)/(*c2.r*d)); s1=angle1*c1.r*c1.r;s2=angle2*c2.r*c2.r;
s3=c1.r*d*sin(angle1);
s=s1+s2-s3; return s;
}
int main()
{
int t;
scanf("%d",&t);
for(int cas = ;cas <= t;cas++)
{
Circle a1,a2,b1,b2;
double R,r;
scanf("%lf%lf",&a1.r,&a2.r);
b1.r=a1.r;
b2.r=a2.r;
scanf("%lf%lf",&a1.x,&a1.y);
scanf("%lf%lf",&b1.x,&b1.y);
a2.x=a1.x;
a2.y=a1.y;
b2.x=b1.x;
b2.y=b1.y;
double ans = ;
ans += calArea(a1,b1);
ans -= calArea(a1,b2);
ans -= calArea(b1,a2);
ans += calArea(a2,b2);
printf("Case #%d: %.6lf\n",cas,ans);
}
}
hdu 5120 Intersection 圆环面积交的更多相关文章
- hdu 5120 Intersection (圆环面积相交->圆面积相交)
Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made up by ...
- hdoj 5120 Intersection 圆环面积求交
Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) Tota ...
- HDU 5120 Intersection (圆的面积交)
题意:给定两个圆环,求两个圆环的面积交. 析:很容易知道,圆环面积交就是,大圆与大圆面积交 - 大圆和小圆面积交 - 小圆和大圆面积交 + 小圆和小圆面积交. 代码如下: #pragma commen ...
- hdu 5120 Intersection
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 A ring is a 2-D figure bounded by two circles sh ...
- hdu 5120 Intersection 两个圆的面积交
Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) P ...
- 计算几何(容斥原理,圆交):HDU 5120 Intersection
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...
- HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...
- HDU 5120 Intersection(几何模板题)
题意:给定两个圆环,求两个圆环相交的面积. 思路:由于圆心和半径不一样,分了好多种情况,后来发现只要把两个圆相交的函数写好之后就不需要那么复杂了.两个圆相交的面积的模板如下: double area_ ...
- Intersection(HDU5120 + 圆交面积)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5120 题目: 题意: 求两个圆环相交的面积. 思路: 两个大圆面积交-2×大圆与小圆面积交+两小圆面 ...
随机推荐
- Ubuntu安装node.js
通过PPA安装Node.js sudo apt-get install python-software-properties sudo add-apt-repository ppa:chris-lea ...
- SQLite支持的SQL数据操作
事务处理 Posted on 2013 年 1 月 1 日 by 林溪 事务为一组SQL命令的集合,这些SQL命令在执行时不可进行分割,即要么全部执行这些SQL命令,要么一个都不进行执行,事务操作 ...
- 宏HASH_INSERT
调用 方法 HASH_INSERT(lock_t, hash, lock_sys->rec_hash,lock_rec_fold(space, page_no), lock); /******* ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.2.7
The set of all invertible matrices is a dense open subset of the set of all $n\times n$ matrices. Th ...
- Spring注释@Qualifier
在学习@Autowired的时候我们已经接触到了@Qualifier, 这节就来详细学习一下自定义@Qualifier. 例如定义一个交通工具类:Vehicle,以及它的子类Bus和Sedan. 如果 ...
- Velocity是如何工作的
当在一个应用程序或者servlet中使用Velocity的时候,你要做如下几个工作: 初始化Velocity.Velocity提供2种使用形式,不管是单一实例模式还是单独运行实例模式,初始化过程都只做 ...
- 解决session失效之后登陆后重新返回之前的页面
在全局拦截器设置保存之前的url存入session中 登陆之后的地址再重session中存 request只用作一次请求 如果页面跳转几次的话原来的url就不存在了建议存在session @Overr ...
- MapReduce 支持的部分数据挖掘算法
MapReduce 支持的部分数据挖掘算法 MapReduce 能够解决的问题有一个共同特点:任务可以被分解为多个子问题,且这些子问题相对独立,彼此之间不会有牵制,待并行处理完这些子问题后,任务便被解 ...
- C/C++动态分配与释放内存的区别详细解析
以下是对C与C++中动态分配与释放内存的区别进行了详细的分析介绍,需要的朋友可以过来参考下 1. malloc()函数1.1 malloc的全称是memory allocation,中文叫动态内存分配 ...
- Bzoj4556: [Tjoi2016&Heoi2016]字符串 后缀数组
4556: [Tjoi2016&Heoi2016]字符串 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 169 Solved: 87[Sub ...