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. jquery $.ajax方法

    $.ajax({ timeout: 3000, cache:false, global:false, type: "POST", url: WEB_URL+"/logic ...

  2. JS的基础语法

    8.运算符号表达式 ①数学运算符 数学运算符有+.-.*./除().%(余数) var a = 10; var b = 5; alert(a+b); 预览以后在网页上弹出的对话框数值就是15. ②逻辑 ...

  3. 基于jQuery很牛X的批量上传插件

    上传功能应该是每个网站必备的工具之一,因此出现了出现了很多各式各样的上传插件! 本文基于个人经验和使用从插件的:交互体验,易用性,文档,美观度出发,为大家推荐三款很NX的批量上传插件! 下面三款插件的 ...

  4. Visual Event插件----查看html元素绑定的事件与方法的利器

    WEB标准提倡结构.表现和行为相 分离,现在越来越多采用这种表现和行为的方式,但它也为我们开发调试带来一些问题,网页载入一堆JavaScript,,我们很难搞清楚最后在哪些元素的哪个动作绑定了事件,尤 ...

  5. Sqli-labs less 47

    Less-47 本关的sql语句为    $sql = "SELECT * FROM users ORDER BY '$id'"; 将id变为字符型,因此根据我们上述提到的知识,我 ...

  6. ISIN编码

    国际证券识别编码(ISIN编码)是由国际标准化组织(ISO)制定的证券编码标准,并在<证券及相关金融工具-国际证券识别编码体系>(ISO6166)中正式发布.ISO6166主要规定了ISI ...

  7. 线性时间常数空间找到数组中数目超过n/5的所有元素

    问题描述: Design an algorithm that, given a list of n elements in an array, finds all the elements that ...

  8. github and SourceTree初步使用

    1.建立连接(一次就行了) 输入你的github名字 2.创建仓库 3.下载仓库 这个时候打开SouceTree就可以看到之前创的仓库了 点击克隆,创建一个文件夹,讲路径设置好 这时候查看本地列表就会 ...

  9. (转)Android学习进阶路线导航线路(Android源码分享)

     转载请注明出处:http://blog.csdn.net/qinjuning 前言:公司最近来了很多应届实习生,看着他们充满信心但略带稚气的脸庞上,想到了去年的自己,那是的我是不是也和 现在的他们一 ...

  10. Java获取最后插入MySQL记录的自增ID值方法

    方法一: String sql = "INSERT INTO users (username,password,email) VALUES (?,?,?);"; PreparedS ...