靠猜答案AC了。。。。。就不放答案了
当时暴力就AC了,其实这道题可以先按照a, b, c优先级排序,然后进行遍历,当前节点和左后一个节点比较,如果小于最后一个节点,直接res++,时间复杂度可以将为O(nlog2n)
以下是暴力代码。。
#include<bits/stdc++.h>
using namespace std;
struct node{
int a;
int b;
int c;
};
int main(){
vector<node> arr;
int count = 0;
int a = 0;
int b = 0;
int c = 0;
int res = 0;
cin >> count;
for (int i = 0; i < count; ++i){
cin >> a >> b >> c;
node temp;
temp.a = a;
temp.b = b;
temp.c = c;
arr.push_back(temp);
}
for (int i = 0; i < count; ++i){
for (int j = 0; j < count; ++j){
if (i == j)
continue;
if (arr[j].a > arr[i].a && arr[j].b > arr[i].b && arr[j].c > arr[i].c){
++res;
break;
}
}
}
cout << res << endl;
return 0;
}

本文分享了一种通过暴力算法解决节点比较问题的方法,作者在比赛中仅凭猜测就实现了问题的解答,通过两层循环遍历所有节点,比较每个节点与其他节点的大小,最终输出符合条件的节点数量。
982

被折叠的 条评论
为什么被折叠?



