标签: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; }
标签:while counter 图片 img 数学 std turn 计算 its
原文地址:https://www.cnblogs.com/wethura/p/9789035.html