uva 11776 - Oh Your Royal Greediness!(暴力)

942 篇文章 2 订阅
232 篇文章 0 订阅

题目链接:11776 - Oh Your Royal Greediness!


题目大意:有n农民,给出每个农民的工作的起始时间和终止时间。然后每个农民在工作的时候都必须有一个监工,问最少需要几个监工。


解题思路:一开始以为是区间选点问题,后来WA了。然后直接暴力就过了。以每个农民的结束时间为标准,若其他人的起始时间小于这个标准,并且终止时间大于这个标准,监工数就要加+1,然后从中选出最大值。


#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

const int N = 1005;
int n;
struct state {
	int x, y;
}s[N];

bool cmp(const state& a, const state& b) {
	return a.x < b.x;
}

void init() {
	for (int i = 0; i < n; i++) scanf("%d %d", &s[i].x, &s[i].y);
	sort(s, s + n, cmp);
}

int solve() {
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int cnt = 0;
		for (int j = 0; j < n; j++) {
			if (s[j].x > s[i].y) break;
		    if (s[j].x <= s[i].y && s[j].y >= s[i].y) cnt++;
		}
		ans = max(ans, cnt);
	}
	return ans;
}

int main() {
	int cas = 1;
	while (scanf("%d", &n) == 1 && n != -1) {
		init();
		printf("Case %d: %d\n", cas++, solve());
	}
	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值