1104. Sum of Number Segments 解析

来源:互联网 发布:新疆网络墙 编辑:程序博客网 时间:2024/06/15 05:34

我按三角形来计算的时候例如

0.1

0.1  0.2 

0.1  0.2  0.3

0.1  0.2  0.3  0.4、

0.2 

0.2  0.3

0.2  0.3  0.4

0.3

0.3   0.4

0.4

估计计算的精度会出现问题。会有一个不能AC/

按照大神们的计算方法可以AC。。到时候再查查什么地方出了问题。


#include <iostream>#define MAX 100010using namespace std;int n;int main() {cin >> n;double temp,sum = 0;for (int i = 1; i <= n; i++) {scanf("%lf", &temp);sum += temp * i * (n - i + 1);}printf("%.2lf\n", sum);return 0;}


0 0