题目链接: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;
}