博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces 157B Trace
阅读量:5237 次
发布时间:2019-06-14

本文共 1971 字,大约阅读时间需要 6 分钟。

B. Trace
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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
11
output
3.1415926536
input
31 4 2
output

40.8407044967

#include 
#include
#include
#include
#include
#include
using namespace std;double pi=2*asin(1.0);int n;double a[105];int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lf",&a[i]); sort(a+1,a+n+1); double sum; if(n&1) { sum=pi*a[1]*a[1]; for(int i=2;i<=n;i+=2) { sum+=pi*(a[i+1]*a[i+1]-a[i]*a[i]); } } else { sum=0; for(int i=2;i<=n;i+=2) { sum+=pi*(a[i]*a[i]-a[i-1]*a[i-1]); } } printf("%lf\n",sum); return 0;}

转载于:https://www.cnblogs.com/dacc123/p/8228644.html

你可能感兴趣的文章
Java实现二分查找
查看>>
架构图-模型
查看>>
黑马程序员_Java基础枚举类型
查看>>
UIImage 和 iOS 图片压缩UIImage / UIImageVIew
查看>>
疯狂JAVA16课之对象与内存控制
查看>>
django ORM创建数据库方法
查看>>
php7 新特性整理
查看>>
RabbitMQ、Redis、Memcache、SQLAlchemy
查看>>
知识不是来炫耀的,而是来分享的-----现在的人们却…似乎开始变味了…
查看>>
口胡:[HNOI2011]数学作业
查看>>
数据库锁机制及乐观锁,悲观锁的并发控制
查看>>
03 线程池
查看>>
手机验证码执行流程
查看>>
python 基础 ----- 变量
查看>>
设计模式课程 设计模式精讲 2-2 UML类图讲解
查看>>
Silverlight 的菜单控件。(不是 Toolkit的)
查看>>
初识lua
查看>>
我是插件狂人,jDuang,jValidator,jModal,jGallery
查看>>
jquery的contains方法
查看>>
python3--算法基础:二分查找/折半查找
查看>>