Cleaning Shifts(POJ 2376 贪心)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 15143 | Accepted: 3875 |
Description
Each cow is only available at some interval of times during the day for work on cleaning. Any cow that is selected for cleaning duty will work for the entirety of her interval.
Your job is to help Farmer John assign some cows to shifts so that (i) every shift has at least one cow assigned to it, and (ii) as few cows as possible are involved in cleaning. If it is not possible to assign a cow to each shift, print -1.
Input
* Lines 2..N+1: Each line contains the start and end times of the interval during which a cow can work. A cow starts work at the start time and finishes after the end time.
Output
Sample Input
3 10
1 7
3 6
6 10
Sample Output
2 区间覆盖问题,贪心
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
struct node
{
int x,y;
}cow[+];
int cmp(node a,node b)
{
if(a.x==b.x) return a.y>=b.y;
return a.x<b.x;
}
int main()
{
int T,N;
int i,j;
freopen("in.txt","r",stdin);
while(scanf("%d%d",&N,&T)!=EOF)
{
for(i=;i<N;i++)
scanf("%d%d",&cow[i].x,&cow[i].y);
sort(cow,cow+N,cmp);
int c=,coun=,j;
bool ans=;
if(cow[].x>)
{
printf("-1\n");
continue;
}
int t=cow[].y+;
while(t<=T)
{
int MaxLen=t;
bool flag=;
int k=c;
for(j=c+;cow[j].x<=t&j<N;j++)
{ if(cow[j].y>=MaxLen)
{
k=j;
MaxLen=cow[j].y;
flag=;
}
}
if(flag==)
{
ans=;
break;
}
c=k;
t=MaxLen+;
coun++;
}
if(ans==) {printf("-1\n");continue;}
printf("%d\n",coun);
}
}
Cleaning Shifts(POJ 2376 贪心)的更多相关文章
- Cleaning Shifts POJ - 2376 (贪心题)
Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31194 Accepted: 7677 ...
- Greedy:Cleaning Shifts(POJ 2376)
牛的大扫除 题目大意:农夫有N只牛,这些牛要帮助打扫农舍,这些牛只能打扫固定位置(千万要注意这个位置不是连续的),每一段区间必须至少有一只牛打扫,问你至少需要多少只牛?(如果区间不能完全被覆盖,则 ...
- bzoj 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 -- 贪心
3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec Memory Limit: 128 MB Description 一天有 ...
- poj-2376 Cleaning Shifts (排序+贪心)
http://poj.org/problem?id=2376 john有n头牛做打扫工作,他想在t时间内每个时间都至少有一头牛在做打扫工作,第一头牛在1,最后一头牛在t时间,每一头牛工作都有一个开始时 ...
- POJ 2376 贪心
题意:FJ希望它的牛做一些清洁工作.有N只牛和T个时间段,每只牛可以承担一段时间内的工作.FJ希望让最小数量的牛覆盖整个T,求出其数量.若无法覆盖整个T,则输出-1. 分析:首先要注意T表示T个时间段 ...
- poj2376 Cleaning Shifts(区间贪心,理解题意)
https://vjudge.net/problem/POJ-2376 题意理解错了!!真是要仔细看题啊!! 看了poj的discuss才发现,如果前一头牛截止到3,那么下一头牛可以从4开始!!! # ...
- POJ 2376 Cleaning Shifts 贪心
Cleaning Shifts 题目连接: http://poj.org/problem?id=2376 Description Farmer John is assigning some of hi ...
- POJ - 2376 Cleaning Shifts 贪心(最小区间覆盖)
Cleaning Shifts Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some clea ...
- 【POJ - 2376】Cleaning Shifts(贪心)
Cleaning Shifts Descriptions: 原文是English,我这就直接上Chinese了,想看原文的点一下链接哦 大表哥分配 N (1 <= N <= 25,000) ...
随机推荐
- 自定义ListView分割线
要完成自定义分割线,我们先来认识一下listview中的两个属性: android:divider 设置list 列表项的分隔条(可用颜色分隔,也可用Drawable分隔) android:divid ...
- LeetCode_Simplify Path
Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", ...
- POJ 2752 Seek the Name, Seek the Fame (KMP next 数组 变形)
题意:给一个字符串S,判断在什么下标的时候,前缀和后缀相等,输出前缀和后缀相等的点. 分析:next数组的一种很巧妙的用法 next数组表示的意义是当前下标前面k字符和开头的前面k个字符相等 所以就会 ...
- 关于Redis
在同步dump.rdb文件时要执行service redis stop后,再拷贝目标rdb文件过去,然后再start 而不是拷贝目标rdb文件过去后直接执行restart 因为redis在执行sto ...
- HtmlHelper扩展 及 页面编码化
Html.Encode 新建Action,命名为HtmlEncodeDemo 将含有特殊字符的值传递给View视图 <%= ViewData["script"] %> ...
- python基础学习05(核心编程第二版)部分
# -*- coding: utf-8 -*- # ==================== #File: python #Author: python #Date: 2014 #========== ...
- Monkey Tradition(中国剩余定理)
Monkey Tradition Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu Submi ...
- [转]CodeIgniter与Zend Acl结合实现轻量级权限控制
Tag :CodeIgniter Zend Acl 权限控制 1. Zend_Acl简介 Zend_Acl 为权限管理提供轻量并灵活的访问控制列表 (ACL,access control list) ...
- 飘逸的python - 解决一个有限制的组合需求
假设有一个团队技能的需求. 这类技能是要集齐所有指定的人就能激活. 但是因为同一个人又2种身份存在,比如杨戬/神杨戬,于是便产生了组合. 这种组合跟普通组合不一样,普通组合可以随意组合.而这种组合是每 ...
- Tomcat 官网知识总结篇
Tomcat 官网知识总结一.Tomcat 基本介绍 1.关键目录 a) bin 该目录包含了启动.停止和启动其他的脚本,如startup.sh.shutdown.sh等; b) conf 配置文件和 ...