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) ...
随机推荐
- jquery中ajax的dataType属性包括哪几项
参考ajax api文档:http://www.w3school.com.cn/jquery/ajax_ajax.asp dataType类型:String预期服务器返回的数据类型.如果不指定,jQu ...
- Oracle字符函数(转换大小写,替换等)
在oracle中,有一些字符函数: upper(字符串):转换为大写lower(字符串):转换为小写initcap(字符串):首字母大写replace(字符串1,字符串2,字符串3):将串1中所有的串 ...
- goldengate介绍
Oracle Golden Gate软件是一种基于日志的结构化数据复制备份软件,它通过解析源数据库在线日志或归档日志获得数据的增量变化,再将这些变化应用到目标数据库,从而实现源数据库与目标数据库同步. ...
- 关于Fragment与Activity的想法
View,Fragment,Activity,ListView等都会涉及到Layout文件 不要从Layout来考虑,而是从Activity,Fragment,来考虑,Layout只是他们的一个属性 ...
- 三元运算符和GridView数据显示
三元运算符嵌套使用:<%# Eval("InsertType").ToString() == "0" ? "数据库" : Eval(& ...
- C51单片机内存优化
52本身有256B的数据存储区,如果没在意一些细节,很容易出现RAM超过128就报错的情况.现讲其问题解释如下: 最常见的是以下两种: ① 超过变量128后必须使用compact模式编译,实际的情况是 ...
- 《Programming WPF》翻译 第7章 4.转换
原文:<Programming WPF>翻译 第7章 4.转换 支持高分辨率显示是WPF中的重要样式.这是被部分地支持--强调了可伸缩的向量图,而不是图像.但是,正如使用GDI+和GDI3 ...
- Linux上的设备管理器
一般windows上我们用它自带的“设备管理器”来查看,管理,安装,卸载驱动. 那么问题来了,Linux上用什么命令来看呢? 可以用: lshw lsusb lspci lsmod 查看特定模块. ...
- ElasticSearch大批量数据入库
最近着手处理大批量数据的任务. 现状是这样的,一个数据采集程序承载大批量数据的存储和检索.后期可能需要对大批量数据进行统计. 数据分布情况 13个点定时生成采集结果到4个文件(小文件生成周期是5分钟) ...
- UVa1587.Digit Counting
题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=247&p ...