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 计算几何的更多相关文章

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

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

  3. 2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229511 时间限制:1s 空间限制:512MB 题目大意: 给定一个n 随后跟着2n行输入 ...

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

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

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

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

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

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

随机推荐

  1. bzoj千题计划191:bzoj2337: [HNOI2011]XOR和路径

    http://www.lydsy.com/JudgeOnline/problem.php?id=2337 概率不能异或 但根据期望的线性,可以计算出每一位为1的概率,再累积他们的期望 枚举每一位i,现 ...

  2. python学习笔记6--操作redis

    一.redis操作 import redis r=redis.Redis(host='211.149.218.16',port=6379,password='123456',db=2) r.set(' ...

  3. 第10月第13天 xcode ipa

    1. xcodebuild -exportArchive -exportFormat ipa -archivePath RongChatRoomDemo\ 17-7-13\ 下午4.04.xcarch ...

  4. c++ 函数指针简单实例

    一开始看函数指针的时候我是很懵的,因为不知道它有什么用,之后慢慢就发现了自己的愚昧无知. 假设我们想实现一个数据结构,比如二叉搜索树,堆.又或者是一个快排,归并排序. 我们一般是直接在两个数要比较的时 ...

  5. python3之SQLAlchemy

    1.SQLAlchemy介绍 SQLAlchemy是Python SQL工具包和对象关系映射器,为应用程序开发人员提供了SQL的全部功能和灵活性. 它提供了一整套众所周知的企业级持久性模式,专为高效和 ...

  6. flask基础之请求钩子(十二)

    前言 什么是请求钩子?在客户端和服务器交互的过程中,有些准备工作或扫尾工作需要统一处理,为了让每个视图函数避免编写重复功能的代码,flask提供了统一的接口可以添加这些处理函数,即请求钩子. 请求钩子 ...

  7. Tomcat优化步骤【转】

    一.Tomcat的缺省是多少,怎么修改 Tomcat的缺省端口号是8080.修改Tomcat端口号:1.找到Tomcat目录下的conf文件夹2.进入conf文件夹里面找到server.xml文件3. ...

  8. [转]使用 mitmproxy + python 做拦截代理

    使用 mitmproxy + python 做拦截代理   本文是一个较为完整的 mitmproxy 教程,侧重于介绍如何开发拦截脚本,帮助读者能够快速得到一个自定义的代理工具. 本文假设读者有基本的 ...

  9. win7下iis中配置php.ini文件

    将php.ini-development配置文件重命名为php.ini配置文件即可. 接着做如下配置操作: 1.修改php.ini配置文件 打开php.ini配置文件,找到 12 ; On windo ...

  10. 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165301

    2018-2019-2 <网络对抗技术>Exp0 Kali安装 Week1 20165301 安装kali 参考此网站 设置共享文件夹 虚拟机->设置->选项->共享文件 ...