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