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).

样例输入

  1. 5 3
  2. 0 1
  3. 1 2
  4. 2 3
  5. 3 2
  6. 6 1

样例输出

  1. 3
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <string>
  7. #include <map>
  8. #include <stack>
  9. #include <queue>
  10. #include <vector>
  11. #define inf 2e9
  12. #define met(a,b) memset(a,b,sizeof a)
  13. typedef long long ll;
  14. using namespace std;
  15. const int N = 1e5+;
  16. const int M = 4e5+;
  17. ll m,t,v;
  18. int cnt=,n;
  19. ll a[N],d[N],j,len;
  20. int LIS(ll *arr, int n){
  21. ll *dp=new ll [n+];
  22. int where, idx = ;
  23. dp[idx] = arr[];
  24. for (int i = ; i < n; ++i){
  25. if (arr[i]>=dp[idx]){
  26. idx++;
  27. dp[idx] = arr[i];
  28. }
  29. else{
  30. where = upper_bound(dp+, dp + idx+, arr[i]) - dp;//非下降
  31. dp[where] = min(dp[where], arr[i]);
  32. }
  33. }
  34. delete[] dp;
  35. return idx;
  36. }
  37.  
  38. int main() {
  39. scanf("%d%lld",&n,&t);
  40. for (int i = ; i <=n; ++i) {
  41. scanf("%lld%lld",&m,&v);
  42. a[i]=m+t*v;
  43. }
  44. for(int i=n;i>;i--){
  45. d[cnt++]=a[i];
  46. }
  47. printf ("%d\n", LIS(d,n));
  48. return ;
  49. }

(寒假集训) 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. ironic rescue standard rescue and unrescue process

    翻译官网救援/取消救援标准流程 1.用户在节点上调用Nova rescue 2.Nova ComputeManager调用virt驱动程序的rescue()方法,传入rescue_password作为 ...

  2. Android数据储存之SharedPreferences总结

    写在前面:本文是我参考李刚老师的<疯狂Android讲义>以及API所写的读书笔记,在此表示感谢,本人小白,如有错误敬请指教. SharedPreferences的使用背景: 有时候,应用 ...

  3. zabbixproxy安装

    目录 1     zabbix3.2安装.... 1 2     安装proxy. 1 2.1      安装zabbix-proxy. 1 2.1.1 配置zabbix yum源.... 1 2.1 ...

  4. 九 DIP 依赖倒置原则

    首先看定义: 1.高层模块不依赖于低层模块,两者都应该依赖于抽象层 2.抽象不能依赖于细节,细节必须依赖于抽象 首先,模块是个抽象的概念,可以大到一个系统中的子系统作为一个模块,也可以是某个子系统中的 ...

  5. vmware设置静态ip(复制)

    一.安装好虚拟后在菜单栏选择编辑→ 虚拟网络编辑器,打开虚拟网络编辑器对话框,选择Vmnet8 Net网络连接方式,随意设置子网IP,点击NAT设置页面,查看子网掩码和网关,后面修改静态IP会用到. ...

  6. ESLint 代码检查规范

    目录 Airbnb Javascript Style Guide 引用 对象 数组 函数 箭头函数 类和构造器 模块 Iterators and Generators 变量 比较运算符 注释 空格 A ...

  7. SQL查询oracle的nclob字段

    使用CONTAINS关键字查询NCLOB字段 SELECT  FORMATTED_MESSAGE    FROM     TBL_LOG WHERE     CONTAINS(FORMATTED_ME ...

  8. Access连接字符串

    Access2007没有密码连接: <connectionStrings> <add name="myconn" connectionString="P ...

  9. crond守护进程

    Linux系统任务计划/etc/crontab cron的主配置文件,可以定义PATHcron格式如下:# .----------------分钟 (0 - 59)# | .------------- ...

  10. BOZJ 2045:疯狂的馒头(并查集)

    题目大意:有n个馒头排成一排,初始时颜色为0,进行m次染色,第i次将(i*p+q)mod n到(i*q+p)mod n的馒头全部染成颜色i,求最后所有馒头颜色.n<=10^6 m<=10^ ...