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) ...
随机推荐
- Codeforces Round #281 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...
- LeetCode_Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...
- 单片机C 语言与汇编语言混合编程
在单片机应用系统设计中,过去主要采用汇编语言开发程序. 汇编语言编写的程序对单片机硬件操作很方便,编写的程序代码短,效率高,但系统设计的周期长,可读性和可移植性都很差.C语言程序开发是近年来单片机系统 ...
- Hibernate逆向工程全过程
前提你已经创建好了数据库,按如下操作进行: 1.添加hibernate.cfg.xml 在src下-->new-->other--->hibernate-->选择“Hibern ...
- 六款主流免费网络嗅探软件wireshark,tcpdump,dsniff,Ettercap,NetStumbler
1.WireShark WireShark是一个开源免费的高性能网络协议分析软件,它的前身就是非常著名的网络分析软 件Ethereal.你可以使用它来解决网络疑难问题,进行网络协议分析,以及作为软件或 ...
- 商派shopex
http://www.shopex.cn/48release/shopexsingle_exper.php 在线体验 前台体验:http://demo.shopex.com.cn/485 后台体验:h ...
- web应用的发布
将web应用打包成.war类型的...因为将其发布到服务器时,其自动解压...非常方便
- Android应用开发学习之状态栏通知
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 状态栏通知涉及到两个类,一是Notification,它代表一个通知:另一个是NotificationManager ...
- Hive 2、Hive 的安装配置(本地MySql模式)
一.前提条件 安装了Zookeeper.Hadoop HDFS HA 安装方法: http://www.cnblogs.com/raphael5200/p/5154325.html 二.安装Mysq ...
- 在Qt中用QAxObject来操作Excel
目录(?)[+] 下一篇:用dumpcpp工具生成的excel.h/excel.cpp来操纵Excel 最近写程序中需要将数据输出保存到Excel文件中.翻看<C++ GUI Pro ...