http://poj.org/problem?id=2376

john有n头牛做打扫工作,他想在t时间内每个时间都至少有一头牛在做打扫工作,第一头牛在1,最后一头牛在t时间,每一头牛工作都有一个开始时间和结束时间,现在让我们找出在每个时间点都有牛打扫的情况下,所用牛越少越好,不能满足输出-1.

首先按起点排序,起点相同就按结束时间长的排序,然后贪心,每次选择时满足      当前牛的开始时间<=上一头牛的结束时间加1,并且当前牛的结束时间最大的一个。

注意 : 不必覆盖只要能连接即可。(1 3     4  6) 是可以的!!!

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1000000000
#define N 1010
using namespace std; struct point
{
int x,y;
}p[];
bool cmp(const point &a,const point &b)
{
if(a.x!=b.x) return a.x<b.x;
else return a.y>b.y;
}
int main()
{
//Read();
//Write()
int n,t;
while(~scanf("%d%d",&n,&t))
{
for(int i=;i<n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
}
sort(p,p+n,cmp);
//for(int i=0;i<n;i++)
// printf("%d %d\n",p[i].x,p[i].y);
if(p[].x!=) {printf("-1\n");continue;}
if(p[].y==t) {printf("1\n");continue;}
int m=p[].y,max=p[].y,ans=,j=;
bool flag;
while()
{
flag=;
for(int i=j+;i<n;i++)
{
if(p[i].x<=m+&&p[i].y>max)
{
flag=;
j=i;
max=p[i].y;
}
}
if(!flag) break;
//printf("%d %d\n",p[j].x,p[j].y);
ans++;
if(max==t)
{
printf("%d\n",ans);
flag=;
break;
}
m=max;
}
if(!flag||max<t) printf("-1\n");
}
return ;
}

poj-2376 Cleaning Shifts (排序+贪心)的更多相关文章

  1. POJ 2376 Cleaning Shifts【贪心】

    POJ 2376 题意: 给出一给大区间和n各小区间,问最少可以用多少小区间覆盖整个大区间. 分析: 贪心法.设t为当前所有已确定区间的最右端,那我们可以每次都取所有可选的小区间(左端点<=t+ ...

  2. ACM学习历程——POJ 2376 Cleaning Shifts(贪心)

    Description Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning ...

  3. poj 2376 Cleaning Shifts(贪心)

    Description Farmer John <= N <= ,) cows to <= T <= ,,), the first being shift and the la ...

  4. POJ 2376 Cleaning Shifts(轮班打扫)

    POJ 2376 Cleaning Shifts(轮班打扫) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] Farmer ...

  5. poj 2376 Cleaning Shifts

    http://poj.org/problem?id=2376 Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  6. POJ 2376 Cleaning Shifts 贪心

    Cleaning Shifts 题目连接: http://poj.org/problem?id=2376 Description Farmer John is assigning some of hi ...

  7. POJ - 2376 Cleaning Shifts 贪心(最小区间覆盖)

    Cleaning Shifts Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some clea ...

  8. poj 2376 Cleaning Shifts 贪心 区间问题

    <pre name="code" class="html"> Cleaning Shifts Time Limit: 1000MS   Memory ...

  9. 【原创】poj ----- 2376 Cleaning Shifts 解题报告

    题目地址: http://poj.org/problem?id=2376 题目内容: Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K ...

  10. poj 2376 Cleaning Shifts 最小区间覆盖

    Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40751   Accepted: 9871 ...

随机推荐

  1. 【转载】Oracle的方案(Schema)和用户(User)的区别

    免责声明:     本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除.     原文作者:立正_敬礼_喊志哥     原文地址:http://my.oschina.ne ...

  2. Phyre LCUE with YEBIS cause issues about GS

    when LCUE enabled in phyreEngine when Yebis integrated and render there are two mainloopdraws in one ...

  3. Fiddler2汉化版使用说明

    fiddler是一款免费且功能强大的数据包抓取软件,它能够快速的抓取HTTP会话以及支持监视.还可设置断点等诸多实用功能,非常适合计算机工作者们分析数据使用.本文就为大家详细介绍一下fiddler的功 ...

  4. C# 对委托的BeginInvoke,EndInvoke 及Control 的BeginInvoke,EndInvoke 的理解

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. POJ 1989

    #include <iostream> #define MAXN 10005 using namespace std; bool mark[MAXN]; int main() { //fr ...

  6. [C++]不能被继承的类

    前面讲到,派生类的构造函数和析构函数会自动调用基类的构造函数和析构函数,那么要让一个类不能被继承,那么就将它的构造函数和析构函数私有函数(派生类可以访问保护函数).那么怎样才能得到该类的实例呢? 这倒 ...

  7. 来认识下less css

    简介 感觉自己都out了,跟不上web时代的潮流了,前不久才刚接触这玩意,发觉lesscss在某些方面还挺有用的,说白了这东西就是一种动态的样式语言,语法类似于css,可以像java那样进行编译,生成 ...

  8. ExtJs之Ext.core.DomQuery

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  9. http://www.cnblogs.com/draem0507/archive/2013/02/01/2889317.html

    http://www.cnblogs.com/draem0507/archive/2013/02/01/2889317.html

  10. Spring学习总结(1)——Spring AOP的概念理解

    1.我所知道的aop 初看aop,上来就是一大堆术语,而且还有个拉风的名字,面向切面编程,都说是OOP的一种有益补充等等.一下子让你不知所措,心想着:怪不得 很多人都和我说aop多难多难 .当我看进去 ...