社区讨论

求Hack,马蜂良好

P5199[USACO19JAN] Mountain View S参与者 3已保存回复 16

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
12 条
当前快照
1 份
快照标识符
@mj2iht3n
此快照首次捕获于
2025/12/12 14:54
2 个月前
此快照最后确认于
2025/12/14 09:20
2 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define div() cout << "\n-----------------------\n";
#define debug(n) cout << #n << " = " << n << "\n";
#define deb(n) cout << #n << " = " << n << "    ";
struct Hill{
	int x,y;
}a[100005],now;
int n,ans;
bool cmp(Hill a, Hill b){
	if(a.x-a.y != b.x-b.y)return a.x-a.y < b.x-b.y;
	else return a.y > b.y;
}
signed main(){
	cin >> n;
	for(int i = 1;i <= n;i++)cin >> a[i].x >> a[i].y;
	sort(a+1,a+n+1,cmp);
	ans = 1;now = a[1];
	for(int i = 2;i <= n;i++){
		if(!(a[i].x-a[i].y >= now.x-now.y && a[i].y+a[i].x <= now.y+now.x)){
			ans++;
			now = a[i];
		}
	}
	cout << ans;
	return 0;
}

回复

16 条回复,欢迎继续交流。

正在加载回复...