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\n",ans);
}
2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem A. Alien Visit 计算几何的更多相关文章
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem D. Distance 迪杰斯特拉
Problem D. Distance 题目连接: http://codeforces.com/gym/100714 Description In a large city a cellular ne ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem C. Contest 水题
Problem C. Contest 题目连接: http://codeforces.com/gym/100714 Description The second round of the annual ...
- 2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator
题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229511 时间限制:1s 空间限制:512MB 题目大意: 给定一个n 随后跟着2n行输入 ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem K. KMC Attacks 交互题 暴力
Problem K. KMC Attacks 题目连接: http://codeforces.com/gym/100714 Description Warrant VI is a remote pla ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem J. Joke 水题
Problem J. Joke 题目连接: http://codeforces.com/gym/100714 Description The problem is to cut the largest ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem I. Interest Targeting 模拟题
Problem I. Interest Targeting 题目连接: http://codeforces.com/gym/100714 Description A unique display ad ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem H. Hometask 水题
Problem H. Hometask 题目连接: http://codeforces.com/gym/100714 Description Kolya is still trying to pass ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem F. Finance 模拟题
Problem F. Finance 题目连接: http://codeforces.com/gym/100714 Description The Big Boss Company (BBC) pri ...
- 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem C. Equivalent Cards 计算几何
Problem C. Equivalent Cards 题目连接: http://www.codeforces.com/gym/100253 Description Jane is playing a ...
随机推荐
- poj 2438 Children's Dining
http://poj.org/problem?id=2438 题意: 有2*N个人要坐在一张圆桌上吃饭,有的人之间存在敌对关系,安排一个座位次序,使得敌对的人不相邻. 假设每个人最多有N-1个敌人.如 ...
- html js点击按钮滚动跳转定位到页面指定位置(DIV)的方法代码
一:通过html锚点实现滚动定位到页面指定位置(DIV): 如果我们要点击实现跳转的地方是一个html锚点,也就是点击一个A标签超链接实现跳转,可以把A标签的href属性直接指向跳转指定位置的d ...
- c++刷题(33/100)笔试题1
笔试总共2小时,三道题,时间挺充裕的,但是最后只做了一道,原因在于自己很浮躁,不审题,不仔细思考.没过的两道都是稍微改一下代码就能过,但是没过就是没过,要引以为戒 题目1: 小W有一个电子时钟用于显示 ...
- linux磁盘已满,文件占用情况
du -sh /data0/* 如上,/data0/* 表示查看data0文件夹下各个目录的磁盘占用情况 df -h 查看总的磁盘占比
- PHP5.6 和PHP7.0区别
1. PHP7.0 比PHP5.6性能提升了两倍. 2.PHP7.0全面一致支持64位. 3.PHP7.0之前出现的致命错误,都改成了抛出异常. 4.增加了空结合操作符(??).效果相当于三元运算符. ...
- requests(三):json请求中中文乱码处理
最近收到一个问题:json格式请求数据中有中文,导致服务端签名失败. 问题详情: 一位同学在发送json格式的post请求时,请求数据中有中文内容: {"inputCodes":[ ...
- tensorboard遇到的坑
<ul><li>No graph definition files were found.</li></ul> <p>启动命令 tensor ...
- Windows命令-系统木马取样
1.前言 工作中偶尔会遇到去现场提取木马样本回公司分析的情况.如果是生产环境下,不方便安装各类抓包.安全软件时.能用系统自带的命令去定位出木马程序相关的信息是最理想不过的状态. 2.Windows常用 ...
- Cling项目demo实现Android+DLNA实现
dlna多屏互动技术在Android和ios上面应用很广,所以自己为了学习,就官方提供的远吗进行了学习. http://4thline.org/projects/cling 由于是一个maven构建的 ...
- ASP.NET中Request.ApplicationPath、Request.FilePath、Request.Path、.Request.MapPath、
1.Request.ApplicationPath->当前应用的目录 Jsp中, ApplicationPath指的是当前的application(应用程序)的目录,ASP.NET中也是这 ...