(寒假集训) 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个数,为 ...
随机推荐
- Python 3基础教程9-函数
本文介绍Python中的函数,主要了解如何定义一个函数,如何调用一个函数. 如果上面你不写调用函数这行代码,你运行后,是没有打印输出的.我们这里来,结合前面的if语句来定义一个,两个数比较,判断最大的 ...
- 孤荷凌寒自学python第五十二天初次尝试使用python读取Firebase数据库中记录
孤荷凌寒自学python第五十二天初次尝试使用python读取Firebase数据库中记录 (完整学习过程屏幕记录视频地址在文末) 今天继续研究Firebase数据库,利用google免费提供的这个数 ...
- 网络--NAT技术
一.概述 1.简介 NAT英文全称是“Network Address Translation”,中文意思是“网络地址转换”,它是一个IETF(Internet Engineering Task For ...
- 手机App测试如何获取包名的入口【两种方式】
在进行手机APP测试的时候经常要获取包名.那么何为包名呢?简单来说其实就是手机APP的安装apk文件的名称,每个手机APP(软件)的包名都是唯一的. 那么我们怎样来获取包名以及包名的入口呢? 方法一: ...
- android配置开发环境
1.下载Java SE并安装. 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 配置环境变量 我的电脑- ...
- VS2017+EF+Mysql生成实体数据模型(解决闪退的坑)
原文:VS2017+EF+Mysql生成实体数据模型(解决闪退的坑) 最近要使用VS2017+EF+Mysql,在生成实体数据模型踏过一些坑,在此做个总结. 1.先下载并安装 mysql-connec ...
- Thread suspend()挂起resume()恢复
import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.Actio ...
- 【bzoj4952】[Wf2017]Need for Speed 二分
题目描述 已知$\sum\limits_{i=1}^n\frac{d_i}{s_i+c}=t$,求$c$ $(d_i>0,s_i+c>0)$ 输入 第一行包含两个整数n(1≤n≤1000) ...
- [LOJ #2162]「POI2011」Garbage
题目大意:给一张$n$个点$m$条边的无向图,每条边是黑色的或白色的,要求变成一个目标颜色.可以从任意一个点开始,走一个简单环,回到开始的点,所经过的边颜色翻转.可以走无数次.问是否有一个方案完成目标 ...
- [CF1045C]Hyperspace Highways
题目大意:给一张$n$个点$m$条边的图,保证若有一个环,一定是完全子图,多次询问两个点之间的最短路径长度 题解:把完全子图缩成一个点,圆方树,方点权值设成$1$,圆点设成$0$即可. 卡点:数组开小 ...