(寒假集训) 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个数,为 ...
随机推荐
- tomcat启动后服务访问404
. 解决办法: 在tomcat文件中有个work文件夹.其中,tomcat属于admin用户,work属于 admin用户 ,启动服务由admin用户启动. 但是发现work文件下的目录权限属于 ...
- # ML学习小笔记—Linear Regression
Regression Output a scalar Model:a set of function 以Linear model为例 y = b+w * $x_cp$ parameters:b,W f ...
- ocrosoft Contest1316 - 信奥编程之路~~~~~第三关 问题 x: 十进制到二进制的转换
http://acm.ocrosoft.com/problem.php?cid=1316&pid=49 题目描述 把十进制到二进制的转换. 输入 234 输出 11101010 样例输入 23 ...
- mysql备份策略
1.备份的种类 完全备份,就是备份整个数据库对象 事务日志备份, 备份事务日志记录上一次的数据库改变 增量备份,也叫差异备份 文件备份 2.备份方式 逻辑备份, 既备份sql语句,使用mysql自带的 ...
- 从 C10K 到 C500K
国外的 Urban Airship 公司的工程师在其官方网志上发文章介绍他们在产品环境中做到 50 万并发客户端,Java + Pure NIO 的实现,最近又有文章介绍针对 Linux Kernel ...
- Spring2集成iBatis2
从数据库中查询一条记录,演示Spring与iBatis的集成 1 编写sqlmaps与Domain对象 <?xml version="1.0" encoding=" ...
- [poj] 1149 PIGS || 最大流经典题目
原题 题目大意 给你m个猪圈以及每个猪圈里原来有多少头猪,先后给你n个人,每个人能打开一些猪圈并且他们最多想买Ki头猪,在每一个人买完后能将打开的猪圈中的猪顺意分配在这次打开猪圈里,在下一个人来之前 ...
- 2017 多校3 hdu 6061 RXD and functions
2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...
- ZJUTACM
描述 这回是浙江工业大学的ACM程序设计竞赛,欢迎你的到来!但是,请稍等!裁判Joe说了,必须正确回答他的问题,才可以看到PIPI的气球MM,KUKU的气球GG.Joe手上有7张卡片,每张卡片上有一个 ...
- windows 下 mySQL 镜像安装文件下载
前言:有时找到的 MySQL 安装文件是 zip 格式的,需要自己配置,自我感觉麻烦,因此记录下下载镜像安装文件过程. 1. 在浏览器里打开mysql的官网http://www.mysql.c ...