codeforces157B
Trace
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.
Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.
Input
The first line contains the single integer n (1 ≤ n ≤ 100). The second line contains n space-separated integers ri (1 ≤ ri ≤ 1000) — the circles' radii. It is guaranteed that all circles are different.
Output
Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10 - 4.
Examples
1
1
3.1415926536
3
1 4 2
40.8407044967
Note
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 12 = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 42 - π × 22) + π × 12 = π × 12 + π = 13π
sol:小学奥数,为了防止丢精度,把R求出来,只用一次π。
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
const double Pi=3.141592653589793238;
int n;
double r[N];
int main()
{
int i;
double R=;
R(n);
for(i=;i<=n;i++) scanf("%lf",&r[i]);
sort(r+,r+n+);
for(i=n;i>=;i-=)
{
R+=r[i]*r[i];
}
for(i=n-;i>=;i-=)
{
R-=r[i]*r[i];
}
printf("%.10lf\n",Pi*R);
return ;
}
/*
input
1
1
output
3.1415926536 input
3
1 4 2
output
40.8407044967
*/
codeforces157B的更多相关文章
随机推荐
- ASP.NET 管道
序号 名称 说明 1 BeginRequest ASP.NET开始处理的第一个时间,表示处理的开始 2 AuthenticateRequest 验证请求,一般用来取得请求的用户信息 3 PostAut ...
- Linux:CentOS7.4新建用户并授权
之前买了一台阿里云服务器,准备用来搭建一些服务,由于使用root用户登录进行操作比较敏感,就新建了一个用户,用来登录并进行日常操作. 这篇博客,介绍下centos7.4下如何新建用户并且授权... 一 ...
- Linux笔记-SIGHUP与daemon
参考资料:linux信号signal和sigaction理解 http://blog.csdn.net/beginning1126/article/details/8680757 signal,此函 ...
- Scala学习(八)练习
Scala中继承&练习 1. 扩展如下的BankAccount类,新类CheckingAccount对每次存款和取款都收取1美元的手续费 class BankAccount ( initial ...
- 在开发框架中使用FTP辅助类上传或者下载文件,方便管理附件内容
在有些系统应用里面,我们需要对应用服务器.数据库服务器.文件服务器进行分开,文件路径等信息存储在数据库服务器里面,但文件内容则存储在文件服务器里面,通过使用FTP进行文件的上传下载,从而实现更加高效的 ...
- Hibernate缓存策略(一级缓存和EHcache二级缓存)
如何配置二级缓存: 第一步:导入EHcache依赖 1)Maven项目: <!--此处使用hibernate4--> <dependency> <groupId>o ...
- Python-模块导入-63
模块导入: # 内置模块 # 扩展的 django # 自定义的 # 文件 # import demo # def read(): # print('my read func') # demo.rea ...
- Python学习第十六篇——异常处理
在实际中,很多时候时候,我们并不能保证我们所写的程序是完美的.比如我们程序的本意是:用户在输入框内输入数字,并进行后续数学运算,即使我们提醒了用户需要输入数字而不是文本,但是有时会无意或者恶意输入字符 ...
- HDFS的命令
.....Hdfs dfs -cat path hadoop fs - 等同 1 -ls 查看当前目录的文件和文件夹 2 -lsr 递归查看 3 -du 查看文件的大小 4-dus 查看文件夹中所有的 ...
- [转帖]SUSE Linux
历经坎坷多次易主,SUSE Linux路在何方? http://blog.itpub.net/11310314/viewspace-2638811/ 之前一直理不清楚 SUSE和RedHat的关系 甚 ...