璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


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 由 温婕莺