zoukankan      html  css  js  c++  java
  • HDU5120

    这题求的是圆环相交的面积,画图可知  圆环相交面积=大交大-2×大交小+小交小

    这题需要用到圆的相交面积公式

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93642#problem/I

    AC代码:

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <math.h>
     4 #include <algorithm>
     5 #define exp 1e-10
     6 #define PI 3.141592654
     7 using namespace std;
     8 typedef long long LL;
     9 struct point
    10 {
    11     double x,y;
    12     point(double x=0,double y=0):x(x),y(y){}
    13 }a,b;
    14 
    15 double dist(point a,point b)
    16 {
    17     double x=(a.x-b.x)*(a.x-b.x);
    18     double y=(a.y-b.y)*(a.y-b.y);
    19     return sqrt(x+y);
    20 }
    21 
    22 double overlap(point c1,double r1,point c2,double r2)
    23 {
    24     double d=dist(c1,c2);
    25     if(r1+r2<d+exp)
    26     {
    27         return 0;
    28     }
    29     if(d<fabs(r1-r2)+exp)
    30     {
    31         double r=min(r1,r2);
    32         return PI*r*r;
    33     }
    34     double x=(d*d+r1*r1-r2*r2)/(2*d);
    35     double t1=acos(x/r1);
    36     double t2=acos((d-x)/r2);
    37     return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);
    38 }
    39 
    40 int main()
    41 {
    42     int T,f;
    43     f=0;
    44     double r,R;
    45     scanf("%d",&T);
    46     while(T--)
    47     {
    48         f++;
    49         scanf("%lf%lf",&r,&R);
    50         scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
    51         double big=overlap(a,R,b,R);
    52         double bigsmall=overlap(a,R,b,r);
    53         double small=overlap(a,r,b,r);
    54         printf("Case #%d: %.6lf
    ",f,big-2*bigsmall+small);
    55     }
    56     return 0;
    57 }
    View Code
  • 相关阅读:
    切片
    类型断言
    方法表达式
    接口
    函数式编程
    多人聊天室
    反射
    yarn基础解释
    webpack基础概念
    ssh登陆报错:packet_write_wait: Connection to x.x.x.x port 22: Broken pipe
  • 原文地址:https://www.cnblogs.com/qioalu/p/4858461.html
Copyright © 2011-2022 走看看