题目分析:
做这道题时自己犯二了,忽略了 的范围,直接将题目想的更简单了。Orz....
看来自己还是弱爆了啊。。。
这道题分类讨论:
Also you could iterate circles, adding distance for each of them and dividing by m2 in the end. Let's see how the i-th iteration works 1 ≤ i ≤ m. Distance to m + i-th circle is 2R. Distance to m + j-th circle, where |j - i| = 1, is . For other circles it's quite simple to calculate sum of distances. There are i - 2 circles which located to the left of current circle. So, sum of distances for these circles is
. In the same manner we can calculate answer for cirlcles which are located to the right of the current circle
以上来自CF Tutorial
下面是代码:
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int m,r;
scanf("%d%d",&m,&r);
double M = m;
double R= r;
double sum = 0;
for(int i = 0; i < m; i++)
{
if(i == 0) sum += 2*R*M;
else if(i == 1) sum += (2*R + sqrt(2)*R)*(2*M-2);
else
{
sum += (2*M-2*i)*(((2*i-2)+sqrt(8))*r);
}
}
printf("%lf\n",sum/m/m);
return 0;
}