UVALive - 7374 Racing Gems 二维非递减子序列
题目链接:
http://acm.hust.edu.cn/vjudge/problem/356795
Racing Gems
Time Limit: 3000MS
#### 问题描述
> You are playing a racing game. Your character starts at the
> x axis (y = 0) and proceeds up the race track, which has a
> boundary at the line x = 0 and another at x = w. You may
> start the race at any horizontal position you want, as long as
> it is within the track boundary. The finish line is at y = h,
> and the game ends when you reach that line. You proceed at
> a fixed vertical velocity v, but you can control your horizontal
> velocity to be any value between −v/r and v/r, and change it at any time.
> There are n gems at specific points on the race track. Your job is to collect as many gems as
> possible. How many gems can you collect?
输入
The input file contains several test cases, each of them as described below.
The first line of input contains four space-separated integers n, r, w, and h (1 ≤ n ≤ 105
, 1 ≤ r ≤ 10,
1 ≤ w, h ≤ 109
). Each of the following n lines contains two space-separated integers xi and yi
, denoting
the coordinate of the i-th gem (0 ≤ xi ≤ w, 0 < yi ≤ h). There will be at most one gem per location.
The input does not include a value for v.
输出
For each case, print, on a single line, the maximum number of gems that can be collected during the
race.
样例
sample input
5 1 10 10
8 8
5 1
4 6
4 7
7 9
5 1 100 100
27 75
79 77
40 93
62 41
52 45
10 3 30 30
14 9
2 20
3 23
15 19
13 5
17 24
6 16
21 5
14 10
3 6sample output
3
3
4
题意
以辆赛车可以从x轴上任意点出发,他的水平速度允许他向每向上移动1个单位,就能向左或向右移动1/r个单位(也就是它的辐射范围是个等腰三角形)
现在赛车从x轴出发,问它在到达终点前能吃到的最多钻石。
题解
考虑每个钻石的向下辐射范围,并且将其投影到x轴上的两个点,(辐射范围与x轴的两个焦点),然后我们就把题目转化成了一个区间覆盖问题,我们用x<y表示x区间被y区间覆盖,即求二维最长的上升子序列:a1<=a2<=...<=an。
我们按每个钻石的左端点排序,然后跑右端点的最长不下降子序列就可以了。由于数据比较大,用二分处理成nlogn的复杂度。
代码
#include<map>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<string>
#define X first
#define Y second
#include<iostream>
#include<algorithm>
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define M (l+(r-l)/2)
#define bug(a) cout<<#a<<" = "<<a<<endl
using namespace std;
typedef __int64 LL;
const int maxn=1e5+10;
struct Node{
LL a,b;
bool operator <(const Node& tmp) const {
return a>tmp.a||a==tmp.a&&b<tmp.b;
}
}nds[maxn];
int n,w,h;
LL r;
LL ra[maxn];
int dp[maxn];
int main() {
memset(dp,0,sizeof(dp));
scanf("%d%I64d%d%d",&n,&r,&w,&h);
for(int i=1;i<=n;i++){
int x,y;
scanf("%d%d",&x,&y);
//映射到x轴的左端点
nds[i].a=r*x-y;
//映射到x轴的右端点
nds[i].b=r*x+y;
}
//按左端点降序排,左端点相同时右端点升序排
sort(nds+1,nds+n+1);
//初始的ra数组为空
int tot=1,ans=1;
for(int i=1;i<=n;i++){
//二分查找
int pos=upper_bound(ra+1,ra+tot,nds[i].b)-ra;
dp[i]=pos;
ra[pos]=nds[i].b;
if(tot==pos) tot++;
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
return 0;
}
UVALive - 7374 Racing Gems 二维非递减子序列的更多相关文章
- UVaLive 7374 Racing Gems (DP,LIS)
题意:以辆赛车可以从x轴上任意点出发,他的水平速度允许他向每向上移动v个单位,就能向左或向右移动v/r个单位(也就是它的辐射范围是个等腰三角形) 现在赛车从x轴出发,问它在到达终点前能吃到的最多钻石. ...
- HDU 5532 Almost Sorted Array (最长非递减子序列)
题目链接 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap s ...
- HDU 6357.Hills And Valleys-字符串非严格递增子序列(LIS最长非下降子序列)+动态规划(区间翻转l,r找最长非递减子序列),好题哇 (2018 Multi-University Training Contest 5 1008)
6357. Hills And Valleys 自己感觉这是个好题,应该是经典题目,所以半路选手补了这道字符串的动态规划题目. 题意就是给你一个串,翻转任意区间一次,求最长的非下降子序列. 一看题面写 ...
- Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列
D. Once Again... You a ...
- hdu5256序列变换(非递减子序列)
题意(中文直接粘吧)序列变换 Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元 ...
- Comet OJ - Contest #6 B.双倍快乐(二维最大上升子序列和)
双倍快乐 题目描述 Illyasviel:"你想要最长不下降子序列吗?" star-dust:"好啊!" Illyasviel:"老板,给我整两个最长 ...
- HDU 6357.Hills And Valleys-动态规划(区间翻转l,r找最长非递减子序列)
题意:给一串由n个数字组成的字符串,选择其中一个区间进行翻转,要求翻转后该字符串的最长非降子序列长度最长,输出这个最长非降子序列的长度以及翻转的区间的左右端点 #include<bits/std ...
- HDU 1025 Constructing Roads In JGShining's Kingdom[动态规划/nlogn求最长非递减子序列]
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- 【坐标变换】【二维偏序】【线段树】Gym - 100820G - Racing Gems
题意:第一象限有n个点,你从x正半轴任选一个位置出发,vy恒定,vx可以任意变化,不过只能在-vy/r到vy/r之间变化,问你最多能经过多少个点. 暴力dp是n^2,不可取. 注意到,一个点,所能到达 ...
随机推荐
- NotePad++相关设置
Notepad++去掉红色下划线: 插件->DSpellCheck->Auto-check Document 前面的勾去掉 Notepad++自动换行: 视图(View)——>自动换 ...
- 怎样用foreach去修改数组之中的数据
$table_exchange=array(1,2,3,4,5,6,7,8); foreach ($table_exchange as $b=>$c){ $table_exchange[$b]= ...
- 2013-10-25笔记,css: mini-width, 标准居中,样式中*号使用,背景图像位置定位
mini-width:设置元素的最小宽度.該屬性值會對元素的寬度設置一個最小限制.因此,元素可以比制定值寬,但不能比制定值窄.不允許指定負值. 完美的居中佈局: body{text-align: ce ...
- iOS中使用子线程的完整方法
http://www.cnblogs.com/ygm900/archive/2013/06/23/3151691.html 第一步:开启子线程 //开启子线程到网络上获取数据 myFirstThrea ...
- C#从数据库读取数据到DataSet并保存到xml文件
using System; using System.Data; using System.Xml; using System.Data.SqlClient; using System.IO; pub ...
- 如何在MySQL中获得更好的全文搜索结果
如何在MySQL中获得更好的全文搜索结果 很多互联网应用程序都提供了全文搜索功能,用户可以使用一个词或者词语片断作为查询项目来定位匹配的记录.在后台,这些程序使用在一个SELECT 查询中的LIKE语 ...
- 小课堂week13 Clean Code Part2
Clean Code Part2 对象与数据结构 首先让我们进行一个严肃的思考,对象与数据结构的区别在哪里? 如下两段代码分别用数据结构和对象的方法来描述了一个Point. public class ...
- 十天学会单片机Day0点亮LED (锁存器、三极管、继电器)
C51常用的数据类型 数据类型 关键字 所占位数 表示数范围 无符号字符型 unsigned char 8 0~255 有符号字符型 char 8 -128~127 无符号整型 unsigned in ...
- public、private、protected 与 默认 等访问修饰符
1)public(公共的):被public修饰的属性和方法可以被所有类访问. 2)private(私有的):被private修饰的属性和方法只能在改类的内部使用. 3)protected(受保护的): ...
- 刀哥多线程现操作gcd-10-delay
延迟操作 // MARK: - 延迟执行 - (void)delay { /** 从现在开始,经过多少纳秒,由"队列"调度异步执行 block 中的代码 参数 1. when 从现 ...