这道题是求排序后有多少个元素大于自己前面的元素吗?
查看原帖
这道题是求排序后有多少个元素大于自己前面的元素吗?
508834
kexinluo楼主2022/5/4 11:55

rt
https://www.luogu.com.cn/record/75054378

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
#define ll long long
#define us unsigned

int n;

struct wood
{
	int l, w;
} a[N];

bool cmp(wood a, wood b)
{
	if (a.w != b.w) return a.w > b.w;
	else return a.l > b.l;
}

int main()
{
	cin >> n;
	for (int i=1; i<=n; i++)
	{
		cin >> a[i].l >> a[i].w;
	}
	sort(a+1, a+n+1, cmp);
	ll ans = 0;
	for (int i=1; i<=n; i++)
	{
		if (a[i].l > a[i-1].l || a[i].w > a[i-1].w) ans ++;
	}
	cout << ans << endl;
	return 0;
}
2022/5/4 11:55
加载中...