hdu5012 圆环相交面积
题中给了 两个同心圆, 一个大圆一个小圆,然后再给了一个大圆一个小圆也是同心圆,求这两个圆环相交的面积,用两个大圆面积减去两倍大小圆面积交加上两个小圆面积交,就ok了
这里算是坑明白了 使用acos的时候要保证不能让大于1或者小于-1的数进来,因此加一个判断,在现场的时候就是这里被坑死了
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
using namespace std;
const double epl =0.0000000001;
const double PI=acos(-1.0);
struct point{
double x,y;
point(double a=, double c=){
x=a; y=c;
}
};
struct Circle{
point c;
double r;
point P(double a){
return point( (c.x+cos(a)*r) ,( c.y+sin(a)*r ) );
}
}P1,P2,C1,C2;
int dcmp(double x){
if(fabs(x)<epl) return ;
return x<?-:;
}
double myz(double a){
if(dcmp(a+1.0)<=) return acos(-1.0);
if(dcmp(a-1.0)>=) return acos(1.0);
return acos(a);
} point operator -(point A, point B){
return point(A.x-B.x,A.y-B.y);
}
bool operator ==(point A, point B){
return dcmp(A.x-B.x)==&&dcmp(A.y-B.y)==;
}
double Dot(point A, point B){
return A.x*B.x+A.y*B.y;
}
double length(point A){
return sqrt(Dot(A,A));
}
double Angle(point A, point B){
return myz(Dot(A,B)/length(A)/length(B));
}
double angle(point v){
return atan2(v.y,v.x);
}
int getdd(Circle C1, Circle C2, point &p1, point &p2){
double d=length(C1.c-C2.c);
if(dcmp(d)==){
return ;
}
if(dcmp(C1.r+C2.r-d)<=) return ;
if(dcmp(fabs(C1.r-C2.r)-d)>=) return ;
double a=angle(C2.c-C1.c);
double da=acos((C1.r*C1.r+d*d-C2.r*C2.r)/(*C1.r*d) );
p1= C1.P(a-da),p2=C1.P(a+da);
if(p1==p2)return ;
return ;
}
double Cross(point A, point B){
return A.x*B.y-A.y*B.x;
}
double Area(point A, point B, point C){
return fabs(Cross(B-A,C-A))/;
}
double solve(Circle A, Circle B){
point pp1, pp2;
int a=getdd(A,B,pp1,pp2);
if(a==) return ;
if(a==) {
double r=min(A.r,B.r);
return r*r*PI;
}
if(dcmp(A.r-B.r)==){
double a=Angle(pp1-A.c,pp2-A.c);
double S=A.r*A.r*PI;
double rate=a/(*PI);
double ans=S*rate-Area(A.c,pp1,pp2);
return ans*2.0;
}else{
if(A.r<B.r){
Circle te =A;
A=B;
B=te;
}
if(dcmp(Cross(pp1-pp2,A.c-pp2) )*dcmp(Cross(pp1-pp2,B.c-pp2))>= ){
double a1= Angle(pp1-A.c,pp2-A.c);
double S1=A.r*A.r*PI;
double rate1=a1/(*PI);
double ans1=S1*rate1-Area(A.c,pp1,pp2);
double a2 = Angle(pp1-B.c,pp2-B.c);
double S2 = B.r*B.r*PI;
double rate2 = a2/(*PI);
double ans2=S2*rate2-Area(B.c,pp1,pp2);
return S2-ans2+ans1;
}else{
double a1= Angle(pp1-A.c,pp2-A.c);
double S1=A.r*A.r*PI;
double rate1=a1/(*PI);
double ans1=S1*rate1-Area(A.c,pp1,pp2);
double a2 = Angle(pp1-B.c,pp2-B.c);
double S2 = B.r*B.r*PI;
double rate2 = a2/(*PI);
double ans2=S2*rate2-Area(B.c,pp1,pp2);
return ans1+ans2;
}
}
}
int main()
{
int T;
scanf("%d",&T);
int cas=;
double x1,x2,y1,y2,r,R;
while(T--){
scanf("%lf%lf",&r,&R);
scanf("%lf%lf",&x1,&y1);
scanf("%lf%lf",&x2,&y2);
P1.c=point(x1,y1);
P2.c=point(x1,y1);
C1.c=point(x2,y2);
C2.c=point(x2,y2);
P1.r=C1.r=R;
P2.r=C2.r=r;
double dada=solve(P1,C1);
double daxi=solve(P1,C2)*;
double xixi=solve(C2,P2);
double ans=dada-daxi+xixi;
printf("Case #%d: %.6lf\n",cas++,ans);
}
return ;
}
hdu5012 圆环相交面积的更多相关文章
- I - Intersection HDU - 5120(圆环相交面积)
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...
- hdu 5120(求两个圆环相交的面积 2014北京现场赛 I题)
两个圆环的内外径相同 给出内外径 和 两个圆心 求两个圆环相交的面积 画下图可以知道 就是两个大圆交-2*小圆与大圆交+2小圆交 Sample Input22 30 00 02 30 05 0 Sam ...
- hdu3060Area2(任意多边形相交面积)
链接 多边形的面积求解是通过选取一个点(通常为原点或者多边形的第一个点)和其它边组成的三角形的有向面积. 对于两个多边形的相交面积就可以通过把多边形分解为三角形,求出三角形的有向面积递加.三角形为凸多 ...
- Gym 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】
J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...
- hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分 圆相交面积 难度:1
Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...
- hdu5858 Hard problem(求两圆相交面积)
题目传送门 Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- hdu 3264 Open-air shopping malls(圆相交面积+二分)
Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDU 3467 (求五个圆相交面积) Song of the Siren
还没开始写题解我就已经内牛满面了,从晚饭搞到现在,WA得我都快哭了呢 题意: 在DotA中,你现在1V5,但是你的英雄有一个半径为r的眩晕技能,已知敌方五个英雄的坐标,问能否将该技能投放到一个合适的位 ...
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...
随机推荐
- url重写(urlrewrite)的一些系统变量
学php也有3年了,一直对url重写不是很了解,本学用到的话都是百度一下,再复制作简单修改,一些变量的参数都不太了解什么意思,难得今天有时间,做个笔记吧! 1)可用的一些系统变量,在重写条件和重写规则 ...
- 集群--LVS的介绍
相关概念 LVS体系结构如图所示,一组服务器通过高速的局域网或者地理分布的广域网相互连接,在它们的前端有一个负载调度器(Load Balancer).负载调度器能无缝地将网络请求调度到真实服务器 ...
- linux系统UDP的socket通信编程
发送方: /* * File: main.c * Author: tianshuai * * Created on 2011年11月29日, 下午10:34 * * 主要实现:发送20个文本消息,然后 ...
- Tomcat优化详细教程
Tomcat是我们经常使用的 servlet容器之一,甚至很多线上产品都使用 Tomcat充当服务器.而且优化后的Tomcat性能提升显著,本文从以下几方面进行分析优化. 一.内存优化 默认情况下To ...
- 基于Cocos2d-x学习OpenGL ES 2.0系列——纹理贴图(6)
在上一篇文章中,我们介绍了如何绘制一个立方体,里面涉及的知识点有VBO(Vertex Buffer Object).IBO(Index Buffer Object)和MVP(Modile-View-P ...
- block基本使用和底层
block基础使用语法 一.block与函数的对比 定义函数指针 int (*myFn)(); 定义Blocks int (^MyBlocks)(int,int); 调用函数指针 (*myFn)( ...
- <转>Logistic回归总结
转自http://blog.csdn.net/dongtingzhizi/article/details/15962797 当我第一遍看完台大的机器学习的视频的时候,我以为我理解了逻辑回归,可后来越看 ...
- LeetCode——Lowest Common Ancestor of a Binary Search Tree
Description: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given no ...
- 借助腾讯云CDN开启全站https及问题解决分享
版权声明:本文由张戈原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/78 来源:腾云阁 https://www.qcloud ...
- Python subprocess shell 编程规范
使用subprocess通过shell调用另一个模块组件时,需要对返回的code进行判断.判断结果为执行失败时需要raise Exception,不然调用树过于复杂时,我们很难跟踪到异常发生的位置.s ...