poj 2376 Cleaning Shifts 区间覆盖
来源:互联网 发布:网络产品线是干什么的 编辑:程序博客网 时间:2024/06/05 03:22
Cleaning Shifts
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 17106 Accepted: 4366
Description
Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things up and has divided the day into T shifts (1 <= T <= 1,000,000), the first being shift 1 and the last being shift T.
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
Line 1: Two space-separated integers: N and T
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.
OutputLine 1: The minimum number of cows Farmer John needs to hire or -1 if it is not possible to assign a cow to each shift.
Sample Input
3 10
1 7
3 6
6 10
Sample Output
2
#include <iostream>#include <cstdio>#include <string.h>#include <climits>#include <algorithm>using namespace std;const int N = 25005;struct intversal{ int begin,end;} aa[N];bool cmp(intversal a,intversal b){ if(a.begin == b.begin) return a.end < b.end; return a.begin < b.begin;}int main(){ int n,T; while(scanf("%d%d",&n,&T) != EOF) { for(int i = 0; i < n; ++i) scanf("%d%d",&aa[i].begin,&aa[i].end); sort(aa,aa+n,cmp); if(aa[0].begin > 1) { printf("-1\n"); continue; } int ans = 1,id = 0; for(int i = 0; i < n; ) { int cnt = 0; for(int j = i + 1; j < n; ++j) { if(aa[j].begin > aa[id].end + 1) break; if(aa[j].begin >= aa[id].begin && aa[j].end >= aa[id].end + 1) { if(aa[j].end > aa[cnt].end) cnt = j; } } if(cnt == 0) { i++; } else { id = cnt; ans++; i = id; } } if(aa[id].end == T) { printf("%d\n",ans); } else printf("-1\n"); } return 0;}
- POJ 2376 Cleaning Shifts 区间覆盖问题
- POJ 2376 Cleaning Shifts (区间覆盖)
- POJ 2376 Cleaning Shifts 区间覆盖
- poj 2376 Cleaning Shifts 区间覆盖
- poj 2376 Cleaning Shifts 区间覆盖
- POJ 题目2376 Cleaning Shifts(区间覆盖)
- POJ 2376 Cleaning Shifts(区间覆盖问题)
- Cleaning Shifts POJ - 2376(区间覆盖,排序+贪心)
- POJ 2376 Cleaning Shifts (贪心区间最少覆盖)
- [poj 2376] Cleaning Shifts [最小区间覆盖 贪心]
- POJ 2376 - Cleaning Shifts(最小区间覆盖)
- poj 3171Cleaning Shifts 区间覆盖
- poj 2376 Cleaning Shifts 贪心 区间问题
- POJ 2376 Cleaning Shifts 【贪心 区间】
- POJ 2376 Cleaning Shifts(贪心,区间问题)
- POJ 2376 Cleaning Shifts 区间贪心
- [POJ 2376] Cleaning Shifts (区间贪心)
- POJ 2376 Cleaning Shifts 区间贪心
- 能ping通Linux但是ssh连不上问题解决方法
- 如何十倍提高你的webpack构建效率
- Linux学习——NFS服务介绍及安装配置方法
- java初始化顺序
- 快速排序-java实现
- poj 2376 Cleaning Shifts 区间覆盖
- 238. Product of Array Except Self
- listView的item中有checkbox,重复被选中的问题
- 我是ATP~
- qnx之resource manager(二)
- Decode Alien Message模拟
- JavaScript异步编程设计快速响应的网络应用
- 安卓应用保活实践(双进程守护)
- 经典面试题-约瑟夫环