1049. 数列的片段和(20)

来源:互联网 发布:淘宝学生女装店 知乎 编辑:程序博客网 时间:2024/06/08 12:32

初次做想当然的用了循环,忽略了时间复杂度的问题。这个错误以后一定要记住别再犯。

// 2017/10/14 NCU // PAT-B 1053// scienceZ#include <cstdio>#include <cmath>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;int n;double t, ans;int main(){    cin >> n;  for (int i = 0; i<n; i++){    cin >> t;    ans+=t*(n-i)*(i+1);  }  printf("%.2lf", ans);  return 0;} 
原创粉丝点击