I - Intersection HDU - 5120(圆环相交面积)
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.
5), 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 x
i, y
i (0 ≤ x
i, y
i ≤ 20) indicating the coordinates of the center of each ring.OutputFor 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
/*
题意:求两个圆环相交的面积 思路:圆环相交面积=外圆1与外圆2相交面积-内圆1与外圆2相交面积-外圆1与内圆2相交面积+内圆1与内圆2相交面积
*/
#include <bits/stdc++.h> #define MAXK 3
#define pi acos(-1) using namespace std; int t;
double r,R;
double x[MAXK],y[MAXK]; double dis(double a1,double b1,double a2,double b2){
return sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2));
} double cal(double a1,double b1,double R,double a2,double b2,double r){
double d=dis(a1,b1,a2,b2);
if(d>=(R+r)){
return 0.0;
}else if(d<=fabs(R-r)){
return min(pi*R*R,pi*r*r);
}else{
if(r>R){
swap(a1,a2);
swap(b1,b2);
swap(R,r);
}
double ok=sqrt(R*R-r*r);
double x=(R*R-r*r+d*d)/(*d);
x=sqrt(R*R-x*x);
double s1=acos(-(*x*x)/(*R*R));
double s2=acos(-(*x*x)/(*r*r));
if(d>=ok){//相交的很小
return (R*R*s1+r*r*s2-*d*x)/;
}else{//相交的很大
return pi*r*r-(r*r*s2-R*R*s1+*d*x)/;
}
} }
int main(){
//freopen("in.txt","r",stdin);
scanf("%d",&t);
for(int ca=;ca<=t;ca++){
printf("Case #%d: ",ca);
scanf("%lf%lf",&r,&R);
for(int i=;i<;i++){
scanf("%lf%lf",&x[i],&y[i]);
}
printf("%.6f\n",cal(x[],y[],R,x[],y[],R)-
cal(x[],y[],R,x[],y[],r)-
cal(x[],y[],r,x[],y[],R)+
cal(x[],y[],r,x[],y[],r));
}
return ;
}
I - Intersection HDU - 5120(圆环相交面积)的更多相关文章
- hdu5012 圆环相交面积
题中给了 两个同心圆, 一个大圆一个小圆,然后再给了一个大圆一个小圆也是同心圆,求这两个圆环相交的面积,用两个大圆面积减去两倍大小圆面积交加上两个小圆面积交,就ok了 这里算是坑明白了 使用acos的 ...
- HDU 5120 Intersection(2014北京赛区现场赛I题 计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5120 解题报告:给你两个完全相同的圆环,要你求这两个圆环相交的部分面积是多少? 题意看了好久没懂.圆环 ...
- hdu 5120 Intersection (圆环面积相交->圆面积相交)
Problem Description Matt is a big fan of logo design. Recently he falls in love with logo made up by ...
- hdu 5120 Intersection 圆环面积交
Intersection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...
- hdu 5120(求两个圆环相交的面积 2014北京现场赛 I题)
两个圆环的内外径相同 给出内外径 和 两个圆心 求两个圆环相交的面积 画下图可以知道 就是两个大圆交-2*小圆与大圆交+2小圆交 Sample Input22 30 00 02 30 05 0 Sam ...
- hdu 5120 Intersection 两个圆的面积交
Intersection Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) P ...
- hdu 5120 (求两圆相交的面积
题意:告诉你两个圆环,求圆环相交的面积. /* gyt Live up to every day */ #include<cstdio> #include<cmath> #in ...
- 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 ...
随机推荐
- Bootstrap对齐方式
<p class="text-left">我居左</p> <p class="text-center">我居中</p& ...
- TCP/IP中你不得不知的十大秘密
这段时间 有一点心很浮躁,不过希望自己马上要矫正过来.好好学习编程!这段时间我想好好地研究一下TCP/IP协议和网络传输这块!加油 一.TCP/IP模型 TCP/IP协议模型(Transmission ...
- C++Builder中MessageBox的基本用法
C++Builder中MessageBox的基本用法 返回值:IDYES=Application->MessageBox("","",MBYESNO) i ...
- 批处理之 for/f 详解
含有/F的for格式:FOR /F ["options"] %%i IN (file) DO command FOR /F ["options"] %%i IN ...
- 使用vs编译事件来动态发布配置文件
我们知道开发有很多的环境,一般我们会分为开发环境,测试环境,生产环境.而我们使用的vs默认配置就两种:Debug和Release.当然vs支持通过配置管理器来添加,编辑及删除配置. 为此不同的环境和配 ...
- JavaWeb(一)之细说Servlet
前言 其实javaWeb的知识早就学过了,可是因为现在在搞大数据开发,所以web的知识都忘记了.准备开始慢慢的把Web的知识一点一点的回忆起来,多学一点没有关系,就怕到时候要用的话,什么都不会了. 一 ...
- HTTP库Axios
前面的话 本文将详细介绍HTTP库Axios 概述 Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中 [安装] 在Vue中使用,最好安装两个模块axios ...
- bzoj4198 荷马史诗 哈夫曼编码
逐影子的人,自己就是影子. --荷马 Allison 最近迷上了文学.她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读她爱不释手的<荷马史诗>.但是由<奥德赛>和&l ...
- Java面向对象 线程技术--上篇
Java面向对象 线程 知识概要: (1)线程与进程 (2)自定义线程的语法结构 (3)多线程概念理解 (4)多线程状态图 (5)多线程--卖票 (6)同 ...
- ubuntu环境下lnmp环境搭建(3)之Php
1.lnmp详细 http://www.discuz.net/thread-3513107-1-1.html 2. 到php目录 http://blog.aboutc.net/linux/65/co ...