1.3 First -- 挤牛奶Milking Cows
解题思路:
数据比较水, 暴力可做
算出时间复杂度发现会T
但是却A了
Accepted code:
/*
ID: halo_mi1
TASK: milk2
LANG: C++
*/
#include<cstdio>
#include<cstring>
#define fre(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
using namespace std;
int n, x, y, Begin, End, ans_1, ans_2, len_1, len_2;
bool a[1000010];
int max(int x, int y) { return x > y ? x : y; }
int min(int x, int y) { return x < y ? x : y; }
int main() {
scanf("%d", &n); memset(a, 0, sizeof(a));
Begin = 1e9;
for (int i = 1; i <= n; i++) {
scanf("%d %d", &x, &y);
Begin = min(Begin, x);
End = max(End, y);
for (int j = x; j < y; j++)
a[j] = 1;
}
ans_1 = len_1 = ans_2 = len_2 = 0;
for (int i = Begin; i < End; i++) {
if (a[i]) len_1++, ans_1 = max(ans_1, len_1), len_2 = 0;
else len_2++, ans_2 = max(ans_2, len_2), len_1 = 0;
}
printf("%d %d", ans_1, ans_2);
}