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) ...
随机推荐
- android获取sdk更新
http://www.th7.cn/Program/Android/201310/154981.shtml 网上许多解决 Android SDK Manager 无法更新(下载)的问题的方法基本都是将 ...
- CoFun 1612 单词分组(容斥)
Description Stan有N个不同的单词,这天,Stan新结交的两个朋友来他这里玩,Stan作为主人,他需要送给他们单词,但由于Stan不能偏心,所以Stan给每个单词一个权值v_i,他需要他 ...
- 编程是一项需要时间来掌握的技能(Anders的经验)
Anders现在每天仍然花大量的时间实际写代码,并且未来会一直写下去.他很清醒的知道自己长处:“相比起管理,我还是更擅长于编程.” 事实上,Anders的成名之作Turbo Pascal通过出售软件授 ...
- CDT+Eclipse代码自动提示
1.查看GCC的版本:$gcc -v————————————————————————gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)———————— ...
- 如何使用WCF调试器WcfTestClient.exe
如果启用服务出现如下异常 请启用下面该服务 C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE 文件->添加服务 地 ...
- linux之chdir函数解析
[lingyun@localhost chdir]$ ls chdir.c [lingyun@localhost chdir]$ cat chdir.c /********************* ...
- RAID,mdadm(笔记)
RAID: 级别:仅代表磁盘组织方式不同,没有上下之分:0: 条带 性能提升: 读,写 冗余能力(容错能力): 无 空间利用率:nS 至少2块盘1: 镜像 性能表现:写性 ...
- JSP错题纠错
A:判断学员是否手动安装过Tomcat(练习熟练度) B:使学员了解Tomcat的运行过程 ,浏览器向Web服务器发送请求,Web站点处理请求后,把处理后的结果响应给浏览器 C:Tomcat作为Web ...
- storm源代码分析---Transactional spouts
Transactionalspouts Trident是以小批量(batch)的形式在处理tuple.而且每一批都会分配一个唯一的transaction id.不同spout的特性不同,一个trans ...
- openssl 对称加密算法enc命令详解
1.对称加密算法概述 openssl的加密算法库提供了丰富的对称加密算法,我们可以通过openssl提供的对称加密算法指令的方式使用,也可以通过调用openssl提供的API的方式使用. openss ...