codeforces 157B Trace

codeforces 157B Trace

题目链接:157B 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.

input
1
1
output
3.1415926536
input
3
1 4 2
output
40.8407044967
题目大意及思路:首先输入一个n,代表有n个半径的圆组成一个多重同心圆,然后输入这n个半径。这几个元组在一起涂颜色并且只能涂红色和蓝色,且相邻的不能涂同一种颜色,注意题目说了最外围的是蓝色(刚开始写这道题时一直没看到,到知错了好几遍也不知道哪错了)然后题目要求的是红色区域的总面积,而同心圆只能是红蓝红蓝·····或者蓝红蓝红······,那么可以从最后一个圆(肯定是红色)往前面扫,最后注意把数组清空成0就行了。

代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

#define debug(x) cerr<<#x<<"="<<x<<endl;
#define m(a,b) memset(a,b,sizeof(a))
#define PI 3.14159265359
typedef long long ll;

int main(){
	int n;
	while(~scanf("%d",&n)){
		int a[105];
		m(a,0);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		sort(a+1,a+1+n);
		double sum=0;
		for(int i=n;i>=1;i-=2){
			sum+=double(PI*(a[i]*a[i]-a[i-1]*a[i-1]));
		}
		printf("%.10lf\n",sum);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值