bzoj 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 -- 贪心
3389: [Usaco2004 Dec]Cleaning Shifts安排值班
Time Limit: 1 Sec Memory Limit: 128 MB
Description
Input
Output
Sample Input
1 7
3 6
6 10
Sample Output
样例说明
奶牛1和奶牛3参与值班即可.
HINT
排序后贪心
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 25010
struct qaz{int l,r;}a[N];
bool cmp(qaz a, qaz b){return a.l==b.l?a.r<b.r:a.l<b.l;}
int n,T,now,cnt,tmp,ans;
int main()
{
scanf("%d%d",&n,&T);
for(int i=;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r);
sort(a+,a+n+,cmp);
while(now<T)
{
tmp=now;
while(cnt<n&&a[cnt+].l<=tmp+){cnt++;now=max(now,a[cnt].r);}
if((cnt==n&&a[cnt].r<T)||(a[cnt+].l>now+)){puts("-1");return ;}
ans++;
}
now<T?puts("-1"):printf("%d\n",ans);
}
bzoj 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 -- 贪心的更多相关文章
- BZOJ 3389: [Usaco2004 Dec]Cleaning Shifts安排值班
题目 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec Memory Limit: 128 MB Description ...
- Bzoj 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 最短路,神题
3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 218 Solved: ...
- 3389: [Usaco2004 Dec]Cleaning Shifts安排值班
3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 102 Solved: ...
- 【BZOJ】3389: [Usaco2004 Dec]Cleaning Shifts安排值班(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=3389 显然左端点排序后,依次取. 要考虑下一次取的方案: 待选点为a[j].x<=a[now] ...
- BZOJ3389: [Usaco2004 Dec]Cleaning Shifts安排值班
3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 45 Solved: ...
- bzoj3389:[Usaco2004 Dec]Cleaning Shifts安排值班
思路:可以贪心,也可以最短路. 贪心写法:因为在保证合法的前提下,我们选择的区间一定要右端点尽量靠后才行,于是我们每次就选择一个合法的并且右端点最靠后的区间就好了(如果没有合法的输出-1即可).时间复 ...
- BZOJ 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
题目 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec Memory Limit: 64 MB Description Farm ...
- [bzoj3389][Usaco2004Dec]Cleaning Shifts安排值班_最短路
Cleaning Shifts bzoj-3389 Usaco-2004Dec 题目大意:每天有n个时间段,每个时间段都必须安排一个奶牛值班.有m个奶牛,每个奶牛只有一个空闲时间s[i]~e[i],求 ...
- bzoj 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚【dp+线段树】
设f[i]为i时刻最小花费 把牛按l升序排列,每头牛能用f[l[i]-1]+c[i]更新(l[i],r[i])的区间min,所以用线段树维护f,用排完序的每头牛来更新,最后查询E点即可 #includ ...
随机推荐
- WAMP允许外部访问的修改方法
apache配置文件httpd.conf里的 "Require local"改" Require all granted"
- Vue-Module
由于使用单一状态树,应用的所有状态会集中到一个比较大的对象.当应用变得非常复杂时,store 对象就有可能变得相当臃肿. 为了解决以上问题,Vuex 允许我们将 store 分割成模块(module) ...
- Linux下多路径multipath配置【转】
一.multipath在redhat 6.2中的基本配置: 1. 通过命令:lsmod |grep dm_multipath 检查是否正常安装成功.如果没有输出说明没有安装那么通过yum功能安装一下 ...
- 64.Minimum Path Sum---dp
题目链接:https://leetcode.com/problems/minimum-path-sum/description/ 题目大意:从左上到右下的路径中,找出路径和最小的路径(与62,63题相 ...
- python的sorted函数对字典按value进行排序
场景:词频统计时候,我们往往要对频率进行排序 sorted(iterable,key,reverse),sorted一共有iterable,key,reverse这三个参数.其中iterable表示可 ...
- oracle日期格式转换 to_date()
与date操作关系最大的就是两个转换函数:to_date(),to_char() to_date() 作用将字符类型按一定格式转化为日期类型: 具体用法:to_date(''2 ...
- linux -j 4
把源码编译成可执行的二进制文件, 4为服务器内核数
- Pandas Installation
1. 将环境变量PATH中加入C:\python2*\Scripts 或者 C:\Program Files\Python 3.5\Scripts 2. 进入pip.exe所在的目录:C:\Progr ...
- unittest单元测试
unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果.今天笔者 ...
- restful的设计风格
网络应用程序,分为前端和后端两个部分.当前的发展趋势,就是前端设备层出不穷(手机.平板.桌面电脑.其他专用设备......). 因此,必须有一种统一的机制,方便不同的前端设备与后端进行通信.这导致AP ...