链接
code
实际上就是统计一共有多少种不同的线段长度,这里用了map,不过估计用set去重也挺方便的
#include <iostream>
#include <map>
using namespace std;
int t, n;
const int N = 50;
int a[N];
map<int, int> mp;
void solve(){
cin >> n;
mp.clear();
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
int ans = 0;
for (int i = 1; i <= n - 1; ++i) {
for (int j = i + 1; j <= n; ++j) {
int dis = a[j] - a[i];
if (!mp[dis]){
++ans;
mp[dis] = 1;
}
}
}
cout << ans << endl;
}
int main(){
cin >> t;
while (t--)
solve();
return 0;
}