码迷,mamicode.com
首页 > 其他好文 > 详细

Permutation Bo (数学证明)

时间:2018-10-15 12:10:15      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:while   counter   图片   img   数学   std   turn   计算   its   

 

当在两端时:共有n * (n - 1)种组合,满足条件的有技术分享图片,计算可得, counter = n * (n - 1) / 2。

其他位置时:共有n * (n - 1) * (n - 2) 种组合,满足条件的有技术分享图片,利用平方和公式计算可得counter = n * (n - 1) * (n - 2)  / 3。

 

 

 

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        double ans = 0.0, c;
        for(int i=1;i<=n;i++){
            scanf("%lf", &c);
            if(i == 1 || i == n) ans += c/2.0;
            else ans += c/3.0;
        }
        printf("%lf\n",ans);
    }
    return 0;
}

 

Permutation Bo (数学证明)

标签:while   counter   图片   img   数学   std   turn   计算   its   

原文地址:https://www.cnblogs.com/wethura/p/9789035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!