题意
n个个位数,求所有组合的两位数之和。不同位置的相同数字其本质不同。
思路
每个数a[i]
个位出现n-1
次,十位也是。所以贡献为a[i] * (n - 1) * 11
。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int& e : a) cin >> e;
int64_t ans = 0;
for (int i = 0; i < n; ++i) {
ans += 1LL * a[i] * 11 * (n - 1);
}
cout << ans << '\n';
return 0;
}
HINT
不定时更新更多题解,Basic Level 全部AC代码,详见 link ! ! !