CodeForces 157B Trace
2 seconds
256 megabytes
standard input
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.
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.
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.
1
1
3.1415926536
3
1 4 2
40.8407044967
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> 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;
}
CodeForces 157B Trace的更多相关文章
- codeforces157B
Trace CodeForces - 157B One day, as Sherlock Holmes was tracking down one very important criminal, h ...
- OUC_Summer Training_ DIV2_#5
这是做的最好的一次了一共做了4道题 嘻嘻~ A - Game Outcome Time Limit:2000MS Memory Limit:262144KB 64bit IO For ...
- HTTP Method详细解读(`GET` `HEAD` `POST` `OPTIONS` `PUT` `DELETE` `TRACE` `CONNECT`)
前言 HTTP Method的历史: HTTP 0.9 这个版本只有GET方法 HTTP 1.0 这个版本有GET HEAD POST这三个方法 HTTP 1.1 这个版本是当前版本,包含GET HE ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- C#指南,重温基础,展望远方!(3)类型和变量
C# 有两种类型:值类型和引用类型. 值类型的变量直接包含数据,而引用类型的变量则存储对数据(称为“对象”)的引用.对于引用类型,两个变量可以引用同一对象:因此,对一个变量执行的运算可能会影响另一个变 ...
- Spring MVC 框架搭建及具体解释
如今主流的Web MVC框架除了Struts这个主力 外.其次就是Spring MVC了,因此这也是作为一名程序猿需要掌握的主流框架.框架选择多了.应对多变的需求和业务时,可实行的方案自然就多了. 只 ...
- python-循环while
while 只要…条件成立,就一直做…. for 循环会在可迭代的序列被穷尽的时候停止,while 则是在条件不成立的时候停止,因此 while 的作用概括成一句话就是:只要…条件成立,就一直做…. ...
- unity5, assert
assert可以实现“三步一岗五步一哨”可以说是保证代码正确性(安全编程)的最有力工具.在用c++写程序的时候assert语句总是要占整个程序的大部分篇幅. 但是转到unity c#,一开始没找到as ...
- Atitit.Base64编码原理与实现设计
Atitit.Base64编码原理与实现设计 1. Base64编码1 1.1. 为什么要用自己的base64编码方案1 2. Base64编码由来1 3. Base64编码原理1 3.1. 具体来说 ...
- [k8s]k8s-web-terminal配置使用 & etcdui etcd browser配置 & etcdkeeper3配置
安装kube-dns后,我想看看他是怎么个配置,于是我就找到了这个 参考: https://github.com/beyondblog/k8s-web-terminal cat >> /e ...
- CvSplit
/* possible split in the tree */ typedef struct CvSplit { CvTreeCascadeNode* parent; CvTreeCascadeNo ...
- plist 与 JOSN的解析
- 页面中添加qq客服
html页面 <html> <head> <meta http-equiv="Content-Type" content="text/htm ...
- hdu6006 Engineer Assignment 状态dp 定义dp[i][s]表示前i个工程状态为s可以执行的最大工程数。s表示前i个工人选走了s状态的工程师。
/** 题目:hdu6006 Engineer Assignment 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6006 题意:已知n个工程,每个需要某 ...