Codeforces Round #195 (Div. 2) B. Vasily the Bear and Fly - 找规律

题目分析:

做这道题时自己犯二了,忽略了 的范围,直接将题目想的更简单了。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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值