417. Heavy Disc
Time limit per test: 0.5 second(s)
Memory limit: 262144 kilobytes
Memory limit: 262144 kilobytes
input: standard
output: standard
output: standard
Consider a heavy disc on the plane, centered at ( x 0 , y 0 ) with radius r , with the origin strictly outside it. The density of the disc is given by formula
What is the mass of the disc?
Input
The input file contains three integer numbers
x
0
,
y
0
,
r
(-100 ≤
x
0
,
y
0
≤ 100, 1 ≤
r
≤ 100,
x
0
2
+
y
0
22
).
Output
Output one real number — the mass of the disc. Your answer will be considered correct if it is within 10
-12
relative error of the exact answer.
Example(s)
sample input | sample output |
3 4 2 | 40.449586576894895 |
【题解】
这道题,真的是,,眼力好的6分钟出来,眼里差的2小时都化简不出来。
题意是这样的:有一个圆,告诉圆心坐标和半径,现在要然你求圆心处的密度,当然,这里的正规算法是要积分化简的,但是!!!看样例。
根据样例,知道圆心坐标,你总要套用题目中给的公式的,套用结果大概是3点多,但是输出的答案是40点多,大概一除,结果是12点多,这和题有什么关系呢?再想想,它是个圆,不外乎周长面积,周长一算,对不上,在算面积,正好12点多,完全对上,不信的话在验证一下,没毛病,就这么简单,也不用积分化简。
这里注意了,ln函数可以直接用log来算,很方便。
【AC代码】
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<cmath>
using namespace std;
const int N = 200;
const double PI = 3.1415926535898;//这里注意精度要大于10^-12次方
int main()
{
int m,n,r;
while(~scanf("%d%d%d",&m,&n,&r))
{
double x = log(m*m+n*n);
x *= r*r*PI;
printf("%.12f\n",x);
}
return 0;
}