Trace

CodeForces - 157B

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

Input
1
1
Output
3.1415926536
Input
3
1 4 2
Output
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的更多相关文章

随机推荐

  1. Jmeter读取Excel,BeanShell取样器调用rt.jar和jxl.jar

    将rt.jar和jxl.jar,放在\apache-jmeter-5.0\lib\ext下面 import java.io.*; import java.util.ArrayList; import ...

  2. IntentService解析

    IntentService中内置了一个HandlerThread,能够对数据进行处理.相比于普通的Service,IntentService有以下优点: 1. 不用在Service创建线程. 2. 不 ...

  3. Groovy语言学习--语法基础(3)

    侧重点可能是groovy metaClass基元类的概念,有点像java的反射,因为java反射目前基本也没研究过,就mark一下,后续若有用到就深入研究一下. 基础语法的东西貌似差不多八九不离十了, ...

  4. python--map()、reduce()

    map()和reduce()是一种在处理大数据时的重要思想,在平时也可以利用.在python中内置了这两个方法,map取映射的意思,reduce取归纳的意思. 一.map() map(func, ls ...

  5. RabbitMQ 高可用之镜像队列

    如果RabbitMQ集群只有一个broker节点,那么该节点的失效将导致整个服务临时性的不可用,并且可能会导致message的丢失(尤其是在非持久化message存储于非持久化queue中的时候).可 ...

  6. oracle 11g空表不能exp导出问题解决方案

    oracle 11g空表不能exp导出问题解决方案 最近由于要进行迁移服务器代码和数据库,突然发现导出的表少了,通过排查发现空表尽然没有exp导出,真是郁闷啊,虽然是空表没数据,但也不能没有啊,如何是 ...

  7. 网络编程-Socket介绍

    Socket介绍 什么是socket?(5分钟) Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.在设计模式中,Socket其实就是一个门面模式,它把复杂的TCP/IP协议 ...

  8. poj2449 第k短路

    题目链接 学习博客:https://blog.csdn.net/Z_Mendez/article/details/47057461 k短路没有我想象的那么难,还是很容易理解的 求s点到t点的第k短路径 ...

  9. sql定时备份

    老规矩,直接上代码: ) set @name='C:\Backup\MyStudy_'+ ),)+'.bak' BACKUP DATABASE[MyStudy]TO DISK=@name WITH N ...

  10. openstack-KVM-Memory

    一.Memory 1.查看memory信息 free -g cat /proc/meminfo dmesg | grep Memory 2.xml文件中的内存信息: vim /etc/libvirt/ ...