题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=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.

题意:求两个相同大小的圆环的面积交。

解法:几何,圆的面积交模板。画一个图应该就能发现公式:圆环面积交=大圆大圆面积交-2×大圆小圆面积交+小圆小圆面积交。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
#define exp 1e-10
#define PI 3.141592654
using namespace std;
typedef long long ll;
struct Point
{
double x,y;
Point (double x=,double y=):x(x),y(y){}
};
double dist(Point a,Point b)
{
double x=(a.x-b.x)*(a.x-b.x);
double y=(a.y-b.y)*(a.y-b.y);
return sqrt(x+y);
}
double Area_of_overlap(Point c1,double r1,Point c2,double r2)
{
double d=dist(c1,c2);
if (r1+r2<d+exp) return ;
if (d<fabs(r1-r2)+exp)
{
double r=min(r1,r2);
return PI*r*r;
}
double x=(d*d+r1*r1-r2*r2)/(*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()
{
int t,ncase=;
double r,R;
Point a,b;
scanf("%d",&t);
while (t--)
{
scanf("%lf%lf",&r,&R);
scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
double bb_area=Area_of_overlap(a,R,b,R);
double bs_area=Area_of_overlap(a,R,b,r);
double ss_area=Area_of_overlap(a,r,b,r);
printf("Case #%d: %.6lf\n",ncase++,bb_area-2.0*bs_area+ss_area);
}
return ;
}

hdu 5120 Intersection的更多相关文章

  1. hdu 5120 Intersection 圆环面积交

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

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

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

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

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

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

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

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

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

  6. HDU 5120 Intersection(几何模板题)

    题意:给定两个圆环,求两个圆环相交的面积. 思路:由于圆心和半径不一样,分了好多种情况,后来发现只要把两个圆相交的函数写好之后就不需要那么复杂了.两个圆相交的面积的模板如下: double area_ ...

  7. HDU 5120 Intersection (圆的面积交)

    题意:给定两个圆环,求两个圆环的面积交. 析:很容易知道,圆环面积交就是,大圆与大圆面积交 - 大圆和小圆面积交 - 小圆和大圆面积交 + 小圆和小圆面积交. 代码如下: #pragma commen ...

  8. 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 ...

  9. HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解

    题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...

随机推荐

  1. asp 301跳转代码

    <%    Response.Status="301 Moved Permanently"     Response.AddHeader "Location&quo ...

  2. centos+php+coreseek+sphinx+mysql之二sphinx配置篇

    先进入文件夹进行以下操作 cd /usr/local/coreseek/etc cp sphinx.conf.dist sphinx.conf source src1 { sql_host = 127 ...

  3. js根据日期获得星期

    var weekday = getWeekday('2013-9-26'); function getWeekday(sDate){ var dt = new Date(sDate.replace(/ ...

  4. grunt初体验

    最近参与多人团队项目开发过程之中,使用到了grunt来构建项目,包括一些文件的压缩,合并等操作.亲自动手进行grunt任务的配置,学到了很多东西.现将自己的学习过程记录如下: 1.对于一个项目而言,使 ...

  5. JSP标记

    JSP标记是JSP页面中很重要的组成部分,JSP标记包括指令标记.动作标记和自定义标记.其中自定义标记主要讲述与Tag文件有关的Tag标记. 一 指令标记page Page指令标记,简称page指令, ...

  6. ViewPage显示Fragment集合实现左右滑动并且出现tab栏--第三方开源--SlidingTabLayout和SlidingTabStrip实现

    注意:有关Fragment的方法和ViewPager的全部是android.support.v4包的,否则会报很多的错误 MainActivity: package com.zzw.fragmentt ...

  7. ajax 注意点

    1. 为了把数据发送到服务器,应该使用POST 方法,为了从服务器检索数据,应该使用GET 方法. 2.ajax 完整参数, url  发送的地址 http://localhost/default.a ...

  8. 实战Django:官方实例Part5

    俗话说,人非圣贤,孰能无过.在堆代码的过程中,即便是老攻城狮,也会写下一些错误的内容.俗话又说,过而能改,善莫大焉.要改,首先要知道哪里存在错误,这便是我们要对投票应用进行测试的原因.   21.撰写 ...

  9. iFreeThinking - 记录生活,分享思考

    http://www.ifreethinking.com iFreeThinking.com 是一个非营利性个人博客网站.开于 2014 年,博客主要记录分享一些思考和感悟. 文章列表:http:// ...

  10. URI与URL的区别

    (原网址:http://zhidao.baidu.com/question/38764759.html) Web上可用的每种资源 - HTML文档.图像.视频片段.程序等 - 由一个通过通用资源标志符 ...