四分之一TLE求评论区debug
查看原帖
四分之一TLE求评论区debug
1805244
yushujian楼主2025/8/5 12:21
#include <bits/stdc++.h>
using namespace std;

int n;

struct HW {
	int h, w;
} hw[3006];

bool cmp(HW x, HW y) {
	if (x.h == y.h)
		return x.w > y.w;
	return x.h > y.h;
} 

int Bubble_sort(HW a[], int x) {
	bool Flag = 1;
	int cnt = 0;
	
	while (Flag) {
		Flag = 0;
		for (int i = 1; i < x; ++i) {
			if (!cmp(a[i], a[i + 1])) {
				Flag = 1;
				cnt++;
				
				HW t = a[i];
				a[i] = a[i + 1];
				a[i + 1] = t;
			}
		}
	}
	
	return cnt;
} 

int main(int argc, char **argv) {
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> hw[i].h >> hw[i].w;
	
	cout << Bubble_sort(hw, n) << endl;
	
	return 0;
} 

提示:错误代码请勿提交。

2025/8/5 12:21
加载中...