我的思路可以吗
查看原帖
我的思路可以吗
847559
Chtholly__Nota楼主2024/5/24 20:44

把高排序,遍历一次,如果高度低于就答案加一

代码:

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
int n,ans=1,now;
long long a[250001];

bool cmp(int x,int y){
	return x>y;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		long long x,y;
		cin>>x>>y;
		a[i]=y;
	}
	sort(a+1,a+1+n,cmp);
	now=a[1];
	for(int i=2;i<=n;i++){
		if(a[i]<now){
			ans++;
			now=a[i];
		}
	}
	cout<<ans;
	return 0;
}
2024/5/24 20:44
加载中...