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. 【Feasibility of Learning】林轩田机器学习基石

    这一节的核心内容在于如何由hoeffding不等式 关联到机器学习的可行性. 这个PAC很形象又准确,描述了“当前的可能性大概是正确的”,即某个概率的上届. hoeffding在机器学习上的关联就是: ...

  2. fiddler如何抓取夜神模拟器上的包

    一.设置Fiddler代理 1.点击Tools-Fiddler Options进入Fiddler Options页面 2.点击Connections,将Fiddler listens on port设 ...

  3. heat应用

    作为OpenStack中的编排引擎,Heat能够出色的完成编排任务,井井有条地管理编排出来的资源.但同时,Heat也是一个出色的应用部署引擎,它提供了一套内置的框架去完成一系列复杂的应用部署任务. 使 ...

  4. leetcode_day01

    任务一:有效的括号 题目链接:https://leetcode-cn.com/problems/valid-parentheses/ 自己的答案: class Solution: def isVali ...

  5. URAL 1732. Ministry of Truth ( KMP 多模式串匹配 )

    问在第一个串中删掉几个字符能否得到第二个串.注意在第二个串中不连续的单词在第一个串中也必须不连续. 一组数据: Input: abababbbbababbb aba ab Output: I HAVE ...

  6. jquery select chosen 动态绑定值

    $("#ddlMstData").find("option[value=" + data.MstKey + "]").attr(" ...

  7. 简单的JS钟表计时

    思路:先写出简单的数字计时,根据时分秒的数值转换成度数,使用CSS3的transform进行div倾斜. 知识点:transform可以对div进行倾斜或旋转等效果.但是根据浏览器不同代码也不同,本代 ...

  8. 【CZY选讲·最大子矩阵和】

    题目描述 有一个n*m的矩阵,恰好改变其中一个数变成给定的常数P,使得改变后的这个矩阵的最大子矩阵最大. 数据范围 n,m<=300. 题解:    ①如果没有p,那么二维矩阵和就是一维最长 ...

  9. clips apache配置虚拟主机

    >>单个虚拟主机 一个一个的配置 1.httpd.conf文件里 Include conf/extra/httpd-vhosts.conf //取消#注释 2.httpd-vhosts.c ...

  10. Mysql建立触发器

    DELIMITER $$ CREATE /*!50017 DEFINER = 'root'@'%' */ TRIGGER `AddTransferAccountLog` AFTER INSERT ON ...