用重载运算符的可以参考一下
查看原帖
用重载运算符的可以参考一下
1427588
zhou_yu_cheng楼主2025/7/28 20:09
#include<bits/stdc++.h>
using namespace std;
int n, t;
struct student {
	int h;
	int w;
	bool operator <(const student& a)const {
		if (h == a.h) return w > a.w;
		return h > a.h;
	}
} s[3010];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s[i].h >> s[i].w;
	}
	while (n--) {
		for (int i = 1; i <= n; i++) {
			if (s[i + 1] < s[i]) {
				swap(s[i], s[i + 1]);
				t++;
			}
		}
	}
	cout << t;
	return 0;
}

2025/7/28 20:09
加载中...