bzoj3389
3389: [Usaco2004 Dec]Cleaning Shifts安排值班
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 367 Solved: 141
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 7
3 6
6 10
Sample Output
样例说明
奶牛1和奶牛3参与值班即可.
HINT
Source
#include <bits/stdc++.h>
using namespace std;
const int N = , inf = 0x3f3f3f3f;
struct line {
int l, r;
} x[N];
int n, t;
int dp[N] ,tree[N << ];
bool cp(line x, line y)
{
if(x.l != y.l) return x.l < y.l;
return x.r > y.r;
}
void update(int l, int r, int x, int pos, int num)
{
if(l == r)
{
tree[x] = min(tree[x], num);
return;
}
int mid = (l + r) >> ;
if(pos <= mid) update(l ,mid ,x << , pos, num);
else update(mid + , r, x << | , pos, num);
tree[x] = min(tree[x << ], tree[x << | ]);
}
int query(int l, int r, int x, int a, int b)
{
if(l > b || r < a) return inf;
if(l >= a && r <= b) return tree[x];
int mid = (l + r) >> ;
return min(query(l, mid, x << , a, b) ,query(mid + , r, x << | , a, b));
}
int main()
{
memset(tree, 0x3f3f, sizeof(tree));
memset(dp, 0x3f3f, sizeof(dp));
scanf("%d%d", &n ,&t);
for(int i = ; i <= n; ++i) scanf("%d%d", &x[i].l, &x[i].r);
sort(x + , x + n + , cp);
if(x[].l != )
{
puts("-1");
return ;
}
dp[x[].r] = ; update(, t, , x[].r, );
for(int i = ; i <= n; ++i)
{
int l = x[i].l, r = x[i].r;
dp[r] = min(dp[r], query(, t, , l - , r) + );
update(, t, , r, dp[r]);
}
printf("%d\n", dp[t] > n ? - : dp[t]);
return ;
}
bzoj3389的更多相关文章
- [bzoj3389][Usaco2004Dec]Cleaning Shifts安排值班_最短路
Cleaning Shifts bzoj-3389 Usaco-2004Dec 题目大意:每天有n个时间段,每个时间段都必须安排一个奶牛值班.有m个奶牛,每个奶牛只有一个空闲时间s[i]~e[i],求 ...
- bzoj3389:[Usaco2004 Dec]Cleaning Shifts安排值班
思路:可以贪心,也可以最短路. 贪心写法:因为在保证合法的前提下,我们选择的区间一定要右端点尽量靠后才行,于是我们每次就选择一个合法的并且右端点最靠后的区间就好了(如果没有合法的输出-1即可).时间复 ...
- BZOJ3389: [Usaco2004 Dec]Cleaning Shifts安排值班
3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 45 Solved: ...
- 8.11-8.16:usaco
summary:57 bzoj1741:裸二分图最大匹配 #include<cstdio> #include<cstring> #include<iostream> ...
- [转载]hzwer的bzoj题单
counter: 664BZOJ1601 BZOJ1003 BZOJ1002 BZOJ1192 BZOJ1303 BZOJ1270 BZOJ3039 BZOJ1191 BZOJ1059 BZOJ120 ...
- BZOJ刷题列表【转载于hzwer】
沿着黄学长的步伐~~ 红色为已刷,黑色为未刷,看我多久能搞完吧... Update on 7.26 :之前咕了好久...(足见博主的flag是多么emmm......)这几天开始会抽时间刷的,每天几道 ...
随机推荐
- poj 3678 XOR和OR和AND(简单2-sat问题)
/* 题意:给你一些边,每条边有一个值和一个运算符XOR OR AND求是否存在一些点使得所有的边根据这些运算符 可以符合条件的权值. 建边方式参考:http://blog.csdn.net/shua ...
- Ubuntu启用IPv6上google的方法
Pv6就是我们通常所说的互联网协议,是TCP/IP的核心协议,那么在Linux下如何开启IPv6呢?下面以Ubuntu为例,给大家介绍下Ubuntu启用IPv6的方法. 方法: $sudo apt-g ...
- [NOIP2001] 提高组 洛谷P1026 统计单词个数
题目描述 给出一个长度不超过200的由小写英文字母组成的字母串(约定;该字串以每行20个字母的方式输入,且保 证每行一定为20个).要求将此字母串分成k份(1<k<=40),且每份中包含的 ...
- DatePickerDialog
package com.pingyijinren.helloworld.activity; import android.app.DatePickerDialog; import android.su ...
- [Android] 随时拍图像处理部分总结及源码分享
http://blog.csdn.net/eastmount/article/details/45492065#comments [Android] 图像各种处理系列文章合集 http://blog. ...
- [Android] 通过GridView仿微信动态添加本地图片
原文:http://blog.csdn.net/eastmount/article/details/41808179 前面文章讲述的都是"随手拍"中图像处理的操作,此篇文章主要讲述 ...
- POJ 1015 Jury Compromise【DP】
罗大神说这题很简单,,,,然而我着实写的很难过... 题目链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110495#proble ...
- CodeForces 596B Wilbur and Array
简单题,一个一个操作,最后就是答案. #include<cstdio> #include<cstring> #include<cmath> #include< ...
- loj516 DP一般看规律(set启发式合并)
题目: https://loj.ac/problem/516 分析: 每次将一个颜色更改为另一个颜色相当于将两个集合合并 然后对于答案的更新,一个点插入到一个集合中,那么可能更新答案的就是其前驱节点或 ...
- [转] Oracle数据库维护常用SQL语句集合
原文地址 进程相关: 1. 求当前会话的SID,SERIAL# SELECT Sid, Serial# FROM V$session WHERE Audsid = Sys_Context ...