Moscow Subregional 2010 Problem A. Alien Visit 计算几何、连续圆的总面积

ACM ICPC 2010-2011 NEERC Moscow Subregional Contest Moscow, October 24, 2010

Problem A. Alien Visit

Time limit: 1 second

Memory limit: 256 megabytes

25 May, 1997, near Elcino-Borisovo place, Jandal region, strange signs were found in the field...

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.

Examples

stdin           stdout

1 1

0

3.1415926536

2 2

0 2

20.2192624343

Source

Moscow Subregional 2010

My Solution

计算几何 计算 一串可能有相交可能有相离的同半径且圆心在同一水平面的圆的总面积

总共是分三类讨论

1、相交, 圆心相距比较远, 相交并且 相交部分在那个菱形里面

2、相交, 圆心相距比较近, 那个菱形在相交部分里面

3、相离, 外离

注意一下精度

然后就是 每次把相交部分算到前一个圆, 然后一次算去就好了

Wrong answer, 然后对圆心排个序就通过了, 本来以为默认就是升序的, 结果是乱序的⊙﹏⊙‖∣

复杂度 O(n)

这个是队友代码实现的, 所以向队友 nardo 要了AC代码

#include<bits/stdc++.h>
using namespace std;

const double pi = acos(-1);
int n;
double r,x,pre,ans = 0.0;
double centers[10000];

int main(){
    cin >> n >> r;
    for(int i = 1;i <= n;++i)
        cin >> centers[i];
    sort(centers + 1,centers + 1 + n);
    pre = -1e9;
    for(int i = 1;i <= n;++i){
        x = centers[i];
        if(x > pre + 2 * r){
            ans += pi * r * r;
        }
        else{
            double dd = x - pre;
            double theta = 2 * acos(dd / 2 / r);
            ans += pi * r * r - (theta * r * r - dd * sqrt(r * r - dd * dd / 4));
        }
        pre = x;
    }
    printf("%.10f",ans);

    return 0;
}

Thank you!

------from ProLights

时间: 2024-11-08 17:14:14

Moscow Subregional 2010 Problem A. Alien Visit 计算几何、连续圆的总面积的相关文章

Moscow Subregional 2010 Problem K. KMC Attacks 交互题、队列优化、枚举

ACM ICPC 2010-2011 NEERC Moscow Subregional Contest Moscow, October 24, 2010 Problem K. KMC Attacks Time limit: 2 seconds Memory limit: 256 megabytes Warrant VI is a remote planet located in the Koprulu Sector. Warrant VI features a strange huge fiel

Moscow Subregional 2010 Problem H. Hometask 转化、素数筛选

ACM ICPC 2010-2011 NEERC Moscow Subregional Contest Moscow, October 24, 2010 Problem H. Hometask Time limit: 1 second Memory limit: 256 megabytes Kolya is still trying to pass a test on Numbers Theory. The lecturer is so desperate about Kolya's knowl

Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造

Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Andrea is a famous science fiction writer, who runs masterclasses for her beloved readers. The most popular one is the

[LeetCode&amp;Python] Problem 811. Subdomain Visit Count

A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leetcode.com". When we visit

2014-2015 ACM-ICPC, NEERC, Eastern Subregional Contest Problem H. Pair: normal and paranormal

题目链接:http://codeforces.com/group/aUVPeyEnI2/contest/229669 时间限制:1s 空间限制:64MB 题目大意:给定一个长度为2n,由n个大写字母和n小写字母组成的字符串,将对应的字母两两连接,且不相交,按顺序输出没个大写字母对应的小写字母的位置,如果不存在则输出"Impossible" 样例: /home/destr/Desktop/深度截图_选择区域_20181006175058.png /home/destr/Desktop/深

2017-2018 ACM-ICPC, NEERC, Moscow Subregional Contest

地址 Rank Solved A B C D E F G H I J 51/298 6/10 O . O O . . O O O . O: 当场通过 ?: 赛后通过 .: 尚未通过 A Advertising Strategy solved by chelly chelly's solution 签到 B Byteland Trip unsolved C Carpet solved by chelly&ch chelly's solution D Decoding of Varints solv

2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest B - Bring Your Own Bombs 离散化+扫描线+计算期望

扫描线一边扫一边算期望,细节比较多. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define PLI pair<LL, int> #define PLL pair<LL, LL> #define ull unsigned long long us

XMOJ 1133: 膜拜大牛 计算几何/两圆相交

1133: 膜拜大牛 Time Limit: 1 Sec  Memory Limit: 131072KiBSubmit: 9619  Solved: 3287 题目连接 http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1133 Description 由于wywcgs是个很菜的菜鸟,所以每到一个新的地方,他都必须去膜拜当地的大牛.但是大牛们都没空理他,所以无可奈何之下,wywcgs只能寻找其他 的办法.为了一次Orz到更多的大牛,他想到了一个好方

UVa12304(计算几何中圆的基本操作)

断断续续写了250多行的模拟,其间被其他事情打扰,总共花了一天才AC吧~ 这道题目再次让我明白,有些事情看起来很难,实际上并没有我们想象中的那么难.当然了我主要指的不是这个题的难度-- 也是初学计算几何,然后居然胆大妄为地不用刘汝佳的思路去实现这些个功能,其中有三个功能是我用自己的思路实现的吧(瞎暴力),最后果然也是自己写的出锅了. 当一个贼长的模拟题交上去一发WA时,我是欲哭无泪的--这让我怎么debug--只好不断安慰自己要用计算几何题去练习耐心. 只是没想到在不断的固执与冷静的试探之下,不