69分求助~
  • 板块P2684 搞清洁
  • 楼主shuhao
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/8/5 11:38
  • 上次更新2024/8/5 13:04:10
查看原帖
69分求助~
1097884
shuhao楼主2024/8/5 11:38

主要思想是让开始时间<=前一个奶牛的结束时间的所有奶牛中选出结束时间最晚的奶牛

#include <bits/stdc++.h>
using namespace std;

const int N = 25000;
int n, t, res = 0, Max;
struct cow {
	int l, r;
	bool operator < (cow o) const {
		return l < o.l;
	}
} a[N];

int main() {
	cin >> n >> t;
	for(int i = 1; i <= n; i++) {
		cin >> a[i].l >> a[i].r;
	}
	sort(a+1, a+n+1);
	for(int i = 1; i <= t; i = Max+1) {
		Max = -0x3f3f3f3f;
		for(int j = 1; j <= n; j++) {
			if(a[j].l <= i)
				Max = max(Max, a[j].r);
		}
		if(Max == -0x3f3f3f3f) {
			cout << -1;
			return 0;
		}
		res++;
	}
	cout << res;
	
    return 0;
}
2024/8/5 11:38
加载中...