USACO section1.2 Milking Cows 挤牛奶(区间覆盖)
题目:http://www.wzoi.org/usaco/12%5C211.asp
额。。。。纠结了很久。。。。
开始没区别时间和时刻。。。。
区间是(star,end]都赋值为1
/*
ID: qiufeih1
PROG: milk2
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
const int INF = 1<<30;
int a[1000001];
int main()
{
freopen("milk2.in", "r", stdin);
freopen("milk2.out", "w",stdout);
int n;
int star, end;
int i, j;
int ans1, ans2;
int count;
int flag;
int min, max;
scanf("%d", &n);
min = INF;
max = -1;
memset(a, 0, sizeof(a));
while (n--)
{
scanf("%d%d", &star, &end);
for (i = star+1; i <= end; i++)//star+1。。。。。
{
a[i] = 1;
}
if (min > star+1)
{
min = star+1;
}
if (max < end)
{
max = end;
}
}
ans1 = ans2 = 0;
count = 1;
for (i = min+1; i <= max; i++)
{
if (a[i] == a[i-1])
{
count++;
}
else
{
if (a[i-1])
{
if (ans1 < count)
{
ans1 = count;
}
}
else
{
if (ans2 < count)
{
ans2 = count;
}
}
count = 1;
}
}
if (ans1 < count)
{
ans1 = count;
}
printf("%d %d\n", ans1, ans2);
return 0;
}
posted on 2012-03-29 12:46 [S*I]SImMon_WCG______* 阅读(424) 评论(0) 编辑 收藏 举报