比赛主页:https://ac.nowcoder.com/acm/contest/52244
A Xor B Problem
思路:
如果i != j代表 (i, j) & (j, i)是两对,也就是说 如果i == j 代表只有一对, 综上得出公式cnt[i] * cnt[i]的累加就是我要的答案
Code:
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 114515; int cnt[N]; ll ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; cnt[x] += 1; } for (int i = 0; i < N; i++) { ans += 1ll * cnt[i] * cnt[i]; } cout << ans << '\n'; return 0; }
标签:cnt,cout,int,vp,补题,ans,GPLT From: https://www.cnblogs.com/youhualiuh/p/18223009