icpc:problems:蓝桥杯_求和
problems | |
---|---|
名称 | 求和 |
题目编号 | 蓝桥杯A2022_C题 |
题目链接 | luogu.com.cn/… |
来源 | Luogu |
算法分类 | 前缀和 |
难易程度 | 容易 |
求和
想法
$$ 0*a_1 + a_1 * a_2 + ( a_1 + a_2 ) * a_3 + ( a_1 + a_2 + a_3 ) * a_4 $$
代码实现
#include<iostream> using namespace std; int main() { long long int n, temp, sum=0, ans=0; cin >> n; for (int i = 0; i < n; ++i) { cin >> temp; ans += sum*temp; sum += temp; } cout << ans; return 0; }
/app/www/public/data/pages/icpc/problems/蓝桥杯_求和.txt · 最后更改: 2023/02/07 09:26 由 温婕莺