(寒假集训) Cow Jog(二分优化的最长上升子数列)
Cow Jog
时间限制: 1 Sec 内存限制: 64 MB
提交: 24 解决: 5
[提交][状态][讨论版]
题目描述
John's N cows (1 <= N <= 100,000) are out exercising their hooves
again, jogging along an infinite track. Each cow starts at a distinct
position on the track, and some cows run at different speeds.
The track is divided into lanes so that
cows may move past each other. No two cows in the same lane may ever
occupy the same position. Farmer John doesn't want any cow to have to
change lanes or adjust speed, and he wonders how many lanes he will need
to accomplish this if the cows are going to run for T minutes (1 <= T
<= 1,000,000,000).
输入
The following N lines each contain the
initial position and speed of a single cow. Position is a nonnegative
integer and speed is a positive integer; both numbers are at most 1
billion. All cows start at distinct positions, and these will be given
in increasing order in the input.
输出
single integer indicating the minimum number of lanes necessary so that
no two cows in the same lane ever occupy the same location (including
at time T).
样例输入
5 3
0 1
1 2
2 3
3 2
6 1
样例输出
3
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 2e9
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = 1e5+;
const int M = 4e5+;
ll m,t,v;
int cnt=,n;
ll a[N],d[N],j,len;
int LIS(ll *arr, int n){
ll *dp=new ll [n+];
int where, idx = ;
dp[idx] = arr[];
for (int i = ; i < n; ++i){
if (arr[i]>=dp[idx]){
idx++;
dp[idx] = arr[i];
}
else{
where = upper_bound(dp+, dp + idx+, arr[i]) - dp;//非下降
dp[where] = min(dp[where], arr[i]);
}
}
delete[] dp;
return idx;
} int main() {
scanf("%d%lld",&n,&t);
for (int i = ; i <=n; ++i) {
scanf("%lld%lld",&m,&v);
a[i]=m+t*v;
}
for(int i=n;i>;i--){
d[cnt++]=a[i];
}
printf ("%d\n", LIS(d,n));
return ;
}
(寒假集训) Cow Jog(二分优化的最长上升子数列)的更多相关文章
- HZNU-ACM寒假集训Day2小结 二分答案
Day2 ---二分 这里直接给出模板 两种对应不同的情况 可以借助数轴理解 int bsearch_1(int l, int r) { while (l < r) { ; if (check( ...
- POJ 3903:Stock Exchange(裸LIS + 二分优化)
http://poj.org/problem?id=3903 Stock Exchange Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- 3893: [Usaco2014 Dec]Cow Jog
3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 174 Solved: 87[Submit] ...
- 51Nod 1090 3个数和为0 set 二分优化
给出一个长度为N的无序数组,数组中的元素为整数,有正有负包括0,并互不相等.从中找出所有和 = 0的3个数的组合.如果没有这样的组合,输出No Solution.如果有多个,按照3个数中最小的数从小到 ...
- 二分优化lis和STL函数
LIS:最长上升子序列: 这个题我们很显然会想到使用dp, 状态设计:dp[i]代表以a[i]结尾的LIS的长度 状态转移:dp[i]=max(dp[i], dp[j]+1) (0<=j< ...
- HDU 1025 LIS二分优化
题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...
- 【bzoj3173】【Tjoi2013】【最长上升子序列】treap+dp二分优化
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=61560361 向大(hei)佬(e)实力学(di ...
- CSU-ACM寒假集训选拔-入门题
CSU-ACM寒假集训选拔-入门题 仅选择部分有价值的题 J(2165): 时间旅行 Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中 ...
- 二分优化的lis
/*此题为一个女大佬教我的,%%%%%%%%%%%%*/ 题目描述 给出1-n的两个排列P1和P2,求它们的最长公共子序列. 输入输出格式 输入格式: 第一行是一个数n, 接下来两行,每行为n个数,为 ...
随机推荐
- SpringMVC<一> 基本结构与配置
刚刚踏入SpringMVC的学习,有一定Strust2的使用经验,边看书看博客,边总结,如有不对的地方还希望各位大佬多多指正. Spring 响应过程与结构 (1)用户在客户端发送一个HTTP请求,W ...
- android DOM解析Xml
文章转自:http://blog.sina.com.cn/s/blog_a661f16c0101d5qp.html People类是自己写的一个类,主要保存各个字符串数据. 由于没学过Xml语法只 ...
- android 使用LruCache缓存网络图片
加载图片,图片如果达到一定的上限,如果没有一种合理的机制对图片进行释放必然会引起程序的崩溃. 为了避免这种情况,我们可以使用Android中LruCache来缓存下载的图片,防止程序出现OOM. ...
- Linux 网卡特性配置ethtool详解
近期遇到一个自定义报文传输性能问题,解决过程中借助了ethtool这个工具,因此发掘一下与此工具相关的网卡的一些特性. ethtool 常用命令如下,比如对eth0的操作: ethtool eth0 ...
- intellij idea 2017 快捷键(提高工作效率)
1.Shift+Enter Annotation annotation = c.getAnnotation(A.class); 这个时候你写代码的时候可能光标在c.getAnno中的某一个位置,那么你 ...
- 再理一下prerouting和postrouting等插入点
这些地方的准确翻译是hook点(hook点是一个土的说法,学名叫rule chain,规则链)这些规则链是内核netfilter架构布置在内核里面的,然后iptables是利用了这套基础架构,想起了内 ...
- P3531 [POI2012]LIT-Letters
题目描述 Little Johnny has a very long surname. Yet he is not the only such person in his milieu. As it ...
- 利用VS2013 XSLT对 XML进行转换
1.打开VS2013 2.文件-->新建-->文件-->XML文件 3.文件-->新建-->文件-->XSLT文件 4.CTRL+SHIFT+S 保存2个文件位置 ...
- [SP10707]COT2 - Count on a tree II
题目大意:有一棵$n$个节点的树,第$i$个点有一个颜色$C_i$,$m$组询问,每次问$x->y$的路径上有多少种颜色 题解:树上莫队,把树按欧拉序展开成一条链,令第$i$个节点第一次出现在序 ...
- 262144 (game)
262144 (game) 题目描述 Bessie likes downloading games to play on her cell phone, even though she does fi ...