[USACO14DEC] Cow Jog_Gold 牛慢跑(金) 洛谷p4873

题意翻译

Farmer John 的 NN 头奶牛 ( 1 ≤ N ≤ 10^5 )(1≤N≤105) 正在一条长度无限的跑道上慢跑,每头奶牛都有一个不同的开始位置,以及不同的跑步速度。

为了方便奶牛们互相超越,整个跑道被分成了若干条赛道。在同一时刻,不可能有在同一条赛道上的两头奶牛占据相同的位置。

现在奶牛们要跑 TT 分钟,在跑步过程中,他们不会改变自己所在的赛道和自己跑步的速度。FJ想要知道,为了奶牛间不会发生冲突,他需要至少准备多少条赛道。

输入格式:第一行包括两个整数 NN 和 TT 。接下来 NN 行,每行两个整数 p_ipi​ 和 v_ivi​ ( p_i , v_i ≤ 10^9 )(pi​,vi​≤109),分别代表奶牛的初始位置和速度。

输出格式:一个整数,代表最少需要的跑道数目。

题目描述

Farmer John's NN cows (1 <= N <= 100,000)(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 TT minutes (1 <= T <= 1,000,000,000).(1<=T<=1,000,000,000).

输入输出格式

输入格式:

 

The first line of input contains NN and TT.

The following NN 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 TT).

 

输入输出样例

输入样例#1: 复制

5 3
0 1
1 2
2 3
3 2
6 1

输出样例#1: 复制

3

若末态位置与初态位置关系发生交叉则会冲突。以初始位置为下标,在末态序列中 的最长上升子序列分割数量 就相当于找最长不上升子序列。

#include<bits/stdc++.h>
#define f(i,l,r) for(i=(l);i<=(r);i++)
using namespace std;
const int MAXN=100005,INF=1e9;
int n,T;
int dp[MAXN];
struct Node{
	long long p,v;
	int id;
	bool operator < (const Node& tmp)const{
		if(v*T+p==tmp.v*T+tmp.p) return p>tmp.p;
		return v*T+p<tmp.v*T+tmp.p;
	}
}a[MAXN];
bool cmp(Node x,Node y)
{
	return x.p<y.p;
}
int main()
{
	ios::sync_with_stdio(false);
	memset(dp,60,sizeof(dp));
	int i,j;
	cin>>n>>T;
	f(i,1,n){
		cin>>a[i].p>>a[i].v;
	}
	sort(a+1,a+1+n,cmp);
	f(i,1,n){
		a[i].id=i;
	}
	sort(a+1,a+1+n);
	f(i,1,n){
		*lower_bound(dp,dp+n,-a[i].id)=-a[i].id;
	}
	cout<<lower_bound(dp,dp+n,INF)-dp<<endl;
	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值