标签:des style blog io ar os 使用 sp for
Description
Input
Output
Sample Input
3 10 1 7 3 6 6 10
Sample Output
2
Hint
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#define inf 0x3fffffff
#define eps 1e-10
using namespace std;
struct node
{
int Begin, End;
}a[25005];
bool cmp(node x, node y)
{
if (x.Begin != y.Begin)
return x.Begin < y.Begin;
else
return x.End > y.End;
}
int t, n;
int qt()
{
int ans = 0;
int now, p, k = 0, Max;
now = 1;
while (now <= t)
{
if (k == n)
return -1;
if (a[k].Begin > now)
return -1;
Max = a[k].End;
while (a[k].Begin <= now && k < n)
{
Max = max(Max, a[k].End);
k++;
}
now = Max + 1;
ans++;
}
return ans;
}
int main()
{
//freopen("test.txt", "r", stdin);
while (scanf("%d%d", &n, &t) != EOF)
{
for (int i = 0; i < n; ++i)
scanf("%d%d", &a[i].Begin, &a[i].End);
sort(a, a+n, cmp);
printf("%d\n", qt());
}
return 0;
}
ACM学习历程——POJ 2376 Cleaning Shifts(贪心)
标签:des style blog io ar os 使用 sp for
原文地址:http://www.cnblogs.com/andyqsmart/p/4116332.html