题目偏水?
查看原帖
题目偏水?
742032
yihang2011楼主2024/10/13 17:03

这题用这么麻烦吗? 不是三次排序就能过吗

感觉不像是T2的思维难度

附上我的代码

#include <iostream>
#include <algorithm>
using namespace std;

int n;

struct node {
	int x, y, z, id;
} a[200010];

int x[200010], y[200010], z[200010];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].x >> a[i].y >> a[i].z;
		a[i].id = i;
	}
	sort(a + 1, a + n + 1, [](node x, node y) {
		return x.x > y.x;
	});
	int now = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i].x != a[i - 1].x) {
			now = i;
		}
		x[a[i].id] = now;
	}
	sort(a + 1, a + n + 1, [](node x, node y) {
		return x.y > y.y;
	});
	now = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i].y != a[i - 1].y) {
			now = i;
		} 
		y[a[i].id] = now;
	}
	sort(a + 1, a + n + 1, [](node x, node y) {
		return x.z > y.z;
	});
	now = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i].z != a[i - 1].z) {
			now = i;
		}
		z[a[i].id] = now;
	}
	for (int i = 1; i <= n; i++) {
		cout << min(x[i], min(y[i], z[i])) << endl;
	}
	return 0;
}

'''

2024/10/13 17:03
加载中...