【bzoj3389】[Usaco2004 Dec]Cleaning Shifts安排值班
来源:互联网 发布:wifi速度测试软件 编辑:程序博客网 时间:2024/05/22 02:22
Description
一天有T(1≤T≤10^6)个时段.约翰正打算安排他的N(1≤N≤25000)只奶牛来值班,打扫
打扫牛棚卫生.每只奶牛都有自己的空闲时间段Si,Ei,只能把空闲的奶牛安排出来值班.而且,每个时间段必需有奶牛在值班. 那么,最少需要动用多少奶牛参与值班呢?如果没有办法安排出合理的方案,就输出-1.
Input
第1行:N,T.第2到N+1行:Si,Ei.
Output
最少安排的奶牛数.
Sample Input
3 10
1 7
3 6
6 10
Sample Output
2
样例说明
奶牛1和奶牛3参与值班即可.
题解
贪心,每次取能取到的最远点。
代码
#include<bits/stdc++.h>#define N 500005#define ll long long#define inf 1000000009#define mod 2010516623LLusing namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}int n,T,R,i,ans;struct node{int l,r;}a[25005];bool cmp(node a,node b){return a.l<b.l;}int main(){ n=read();T=read(); for (i=1;i<=n;i++) a[i].l=read(),a[i].r=read(); sort(a+1,a+n+1,cmp); i=1; while (R!=T&&i<=n) { int r=0; for (;i<=n&&a[i].l<=R+1;i++) r=max(r,a[i].r); ans++;R=r; if (R==0) return puts("-1"),0; } if (R!=T) puts("-1");else printf("%d",ans); return 0;}
阅读全文
0 0
- bzoj3389 [Usaco2004 Dec]Cleaning Shifts安排值班
- bzoj3389: [Usaco2004 Dec]Cleaning Shifts安排值班
- 【bzoj3389】[Usaco2004 Dec]Cleaning Shifts安排值班
- bzoj 3389 [Usaco2004 Dec]Cleaning Shifts安排值班
- 【BZOJ】3389: [Usaco2004 Dec]Cleaning Shifts安排值班
- [usaco2004 dec]打扫机房II-Pku2376 Cleaning Shifts(区间问题)
- bzoj1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
- BZOJ1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
- 【bzoj1672】[Usaco2005 Dec]Cleaning Shifts 清理牛棚
- bzoj1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
- [BZOJ1672]Usaco 2005 Dec Cleaning Shifts 清理牛棚
- bzoj 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚(DP)
- Cleaning Shifts
- Cleaning Shifts
- Cleaning Shifts
- - Cleaning Shifts
- Cleaning Shifts
- Cleaning Shifts
- mysql常用命令
- 387. First Unique Character in a String
- java类加载
- 关于设计模式的几点经验分享
- 前端开发 将table内容导出到excel
- 【bzoj3389】[Usaco2004 Dec]Cleaning Shifts安排值班
- 5.5
- 程序执行概述
- matplotlib的一些基本设置的记录
- Retrofit2源码解析03-OkHttpCall.enqueue
- JVM每小时执行一次FULL GC问题
- 在eclipse中配置tomcat
- Spring 自动装配Bean属性
- 《白话深度学习与Tensorflow》学习笔记(2)梯度下降、梯度消失、参数、归一化