本题感想:
本题主要是应该避免重复比较,以a,b,c,d为例,我们假设先a不动,依次比较d,c,b或者b,c,d,然后假设 b不动,依次比较c,d,最后假设c不动,比较d,这样这道题就差不多解决了
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int a[1010][3], s[1010] = { 0 }, t = 0;//t计数
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][j];
s[i] += a[i][j];
}
}
for (int i = 0; i < n - 1; i++) {//从前与后进行比较,避免重复
for (int d = n - 1; d > i; d--) {
if (fabs(a[i][0] - a[d][0]) <= 5 &&
fabs(a[i][1] - a[d][1]) <= 5 &&
fabs(a[i][2] - a[d][2]) <= 5
&&fabs(s[i] - s[d]) <= 10)
t++;
}
}
cout << t;
}
标签:洛谷,int,深基,cin,C++,++,include,1010,比较
From: https://blog.csdn.net/2301_81266471/article/details/140265522