CodeForces 157B Trace
2016-05-07 07:48
519 查看
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
output
input
output
40.8407044967
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
1 1
output
3.1415926536
input
3 1 4 2
output
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 157A Game Outcome
- CodeForces 157A Game Outcome
- win7任务栏图标显示异常的解决方法
- 动态链接库DLL的加载:隐式加载(载入时加载)和显式加载(运行时加载)
- HDU 3578 Greedy Tino(双塔DP)
- 第一个DLL程序:动态链接库DLL教程,30分钟快速上手
- HDU 3578 Greedy Tino(双塔DP)
- POJ 2609 Ferry Loading(双塔DP)
- POJ 2609 Ferry Loading(双塔DP)
- 最小-最大计划报表-无法生成申请
- setContentView( )方法
- 数据科学家应该掌握的12种机器学习算法
- 吃了程序员这碗青春饭 40岁你该怎么办?
- setContentView( )方法
- 月入十万真的难吗?
- POJ 1015 Jury Compromise(双塔DP)
- POJ 1015 Jury Compromise(双塔DP)
- 用浏览器(支持WebSocket)和node-inspector 调试后端(CoffeeScript,Typescript)代码
- 持续交付之一——软件交付的问题
- Adb connection Error:远程主机强迫关闭了一个现有的连接