zoukankan      html  css  js  c++  java
  • 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem A. Alien Visit 计算几何

    Problem A. Alien Visit

    题目连接:

    http://codeforces.com/gym/100714

    Description

    Witness: “First, I saw only one UFO. It was shining with cold-blue light. Closer to the center of the
    object, the light was pink. It hung over the field, then began to blink and move intermittently round. The
    UFO was quite big. The second UFO came several minutes after the first. It had the same size as the first
    one. It seemed that there was some kind of contact between them — they began to blink alternately.”
    Circles of scorched barley were found in the field. The circles were of the same radius, and their centers
    were lying on a straight line.
    You were hired to investigate the damage caused to the farms of Elcino-Borisovo place by the visit of
    aliens. In order to do this you are to calculate the total area of scorched barley.

    Input

    The first line of the input contains two integers n and r denoting number of circles and the radius of the
    circles, respectively (1 ≤ n ≤ 1 000, 1 ≤ r ≤ 100). The next line contains n space separated integers
    a1, a2, . . . , an — the shifts of circles’ centers relative to some origin (0 ≤ ai ≤ 5 000). All shifts are
    guaranteed to be distinct.

    Output

    Output the only real number — the total area covered by these circles. The relative error of your answer
    must not exceed 10−6
    .

    Sample Input

    1 1
    0

    Sample Output

    3.1415926536

    Hint

    题意

    给你n个在x轴的圆,半径都是r,问你总共的面积是多少

    题解:

    就总的面积减去两两相交的面积就好了,咩。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    //两圆公共面积:
    // 必须保证相交
    const double PI = acos(-1.0);
    struct POINT
    {
     double x;
     double y;
     POINT(double a=0, double b=0) { x=a; y=b;} //constructor
    };
    double c2area(POINT A,double r1,POINT B,double r2){
        double rx1=A.x,ry1=A.y,rx2=B.x,ry2=B.y;
        double drma=sqrt((rx1-rx2)*(rx1-rx2)+(ry1-ry2)*(ry1-ry2));
        double a1=acos((r1*r1+drma*drma-r2*r2)/(2.0*r1*drma));
        double a2=acos((r2*r2+drma*drma-r1*r1)/(2.0*r2*drma));
        double res=(a1*r1*r1+a2*r2*r2-r1*drma*sin(a1));
        return res;
    }
    double dis(POINT A,POINT B){
        return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
    }
    bool cmp(POINT A,POINT B){
        if(A.x==B.x)return A.y<B.y;
        return A.x<B.x;
    }
    POINT p[5005];
    int main(){
        int n;double r;
        scanf("%d%lf",&n,&r);
        for(int i=1;i<=n;i++){
            scanf("%lf",&p[i].x);
            p[i].y=0;
        }
        sort(p+1,p+1+n,cmp);
        double ans = n*PI*r*r;
        for(int i=1;i<n;i++){
            if(2*r>dis(p[i],p[i+1])){
                ans-=c2area(p[i],r,p[i+1],r);
            }
        }
        printf("%.12f
    ",ans);
    }
  • 相关阅读:
    POJ 1269 Intersecting Lines(判断两条线段关系)
    POJ 3304 Segments(判断直线和线段相交)
    poj 1383 Labyrinth【迷宫bfs+树的直径】
    poj 2631 Roads in the North【树的直径裸题】
    poj 1985 Cow Marathon【树的直径裸题】
    hdoj 1596 find the safest road【最短路变形,求最大安全系数】
    hdoj 1260 Tickets【dp】
    poj 1564 Sum It Up【dfs+去重】
    2014 牡丹江现场赛 i题 (zoj 3827 Information Entropy)
    hdoj 2473 Junk-Mail Filter【并查集节点的删除】
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5750711.html
Copyright © 2011-2022 走看看