Cow Jog

时间限制: 1 Sec  内存限制: 64 MB
提交: 24  解决: 5
[提交][状态][讨论版]

题目描述

Farmer
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 first line of input contains N and T.

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.

输出

A
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(二分优化的最长上升子数列)的更多相关文章

  1. HZNU-ACM寒假集训Day2小结 二分答案

    Day2 ---二分 这里直接给出模板 两种对应不同的情况 可以借助数轴理解 int bsearch_1(int l, int r) { while (l < r) { ; if (check( ...

  2. POJ 3903:Stock Exchange(裸LIS + 二分优化)

    http://poj.org/problem?id=3903 Stock Exchange Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  3. 3893: [Usaco2014 Dec]Cow Jog

    3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 174  Solved: 87[Submit] ...

  4. 51Nod 1090 3个数和为0 set 二分优化

    给出一个长度为N的无序数组,数组中的元素为整数,有正有负包括0,并互不相等.从中找出所有和 = 0的3个数的组合.如果没有这样的组合,输出No Solution.如果有多个,按照3个数中最小的数从小到 ...

  5. 二分优化lis和STL函数

    LIS:最长上升子序列: 这个题我们很显然会想到使用dp, 状态设计:dp[i]代表以a[i]结尾的LIS的长度 状态转移:dp[i]=max(dp[i], dp[j]+1) (0<=j< ...

  6. HDU 1025 LIS二分优化

    题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...

  7. 【bzoj3173】【Tjoi2013】【最长上升子序列】treap+dp二分优化

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=61560361 向大(hei)佬(e)实力学(di ...

  8. CSU-ACM寒假集训选拔-入门题

    CSU-ACM寒假集训选拔-入门题 仅选择部分有价值的题 J(2165): 时间旅行 Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中 ...

  9. 二分优化的lis

    /*此题为一个女大佬教我的,%%%%%%%%%%%%*/ 题目描述 给出1-n的两个排列P1和P2,求它们的最长公共子序列. 输入输出格式 输入格式: 第一行是一个数n, 接下来两行,每行为n个数,为 ...

随机推荐

  1. 命名空间“System.Web.Http”中不存在类型或命名空间名称“Description”(是否缺少程序集引用?)

    solution: Set "Copy Local : True" in properties for References\System.Web.Http   在http://s ...

  2. cookie不能删除

    cookie不仅仅包含一个键值对,还包含域 domain  路径path, 一般domain是请求的地址 www.baidu.com/news.html 那domain就是www.baidu.com ...

  3. Android记事本开发04

    昨天: 显式intent 隐身intent 今天: intentFilter 问题: 无法直接预览布局文件的效果.

  4. 软工实践Alpha冲刺(8/10)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 已经解决登录注册等基本功能的界面. 完成非功能的主界面制作 ...

  5. zoj 1508 Intervals (差分约束)

    Intervals Time Limit: 10 Seconds      Memory Limit: 32768 KB You are given n closed, integer interva ...

  6. [codeforces] 526D [51nod] 1554 欧姆诺姆和项链

    原题 KMP 方法一: 听说是ex-kmp--来自学姐 ex-kmp是处理两个串s和t之间,t的每一个后缀在s中的最长前缀的长度的一个算法. 它很像manacher(至少我和学姐这么认为),记录了一个 ...

  7. Codeforces Round #504:D. Array Restoration

    D. Array Restoration 题目链接:https://codeforces.com/contest/1023/problem/D 题意: 给出一个序列,现在要求对一个全为0的序列执行q次 ...

  8. bzoj 4455 [Zjoi2016]小星星 树形dp&容斥

    4455: [Zjoi2016]小星星 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 643  Solved: 391[Submit][Status] ...

  9. Access-Control-Allow-Origin设置多个域名

    Access-Control-Allow-Origin只能返回一个. 所以用以下方法实现多个白名单域名:创建一个数据,获取请求中origin,如果在数组里,就返回该origin,如果不在,就返回一个默 ...

  10. laravel的elixir和gulp用来对前端施工

    使用laravel elixer npm install --global gulp  ok 然后在安装好的laravel 下 npm install 以安装 laravel-elixir subli ...