二维LIS Gym100820G Racing Gems
来源:互联网 发布:知不足者好学的下一句 编辑:程序博客网 时间:2024/06/05 04:30
传送门:点击打开链接
题意:一个赛车捡金币的游戏,刚开始的起点在x轴,赛车跑道宽为w,最左边是y轴。刚开始你可以选择在x轴的任意位置启动。有很多金币在赛道中,位置已经告诉你。还告诉了你一个r,当y轴方向的车速为v时,x轴的车速只能在[-v/r,v/r]这个区间中,说白了就是在y轴上移动s距离,x轴上只能移动[-w/r,w/r]距离。赛车在y轴方向只能朝正方向移动。问到达终点时,最多能拾到多少金币。
思路:把题目转换一下就能发现,当赛车在某个位置时,它接下来能拾到的金币的位置是跑道的位置和两条射线夹的面积的相交部分。假如我们让这两条射线分别与赛道两旁的边界相交,那么就能得到两个数字,分别记为a,b
最后我们能发现,本身是一个DAG模型,但是由于都很庞大,但是转换成(a,b) 以后,如果想捡了这个金币后还能捡到下一个金币,那么就要保证下一个金币的A比a大且B比b大,也可以相等。那么这就变成了一个二维无序LIS了,有一种很简单的方法就是,把a从小到大排序,那么之后对b做最长不下降子序列,那么就是答案了。因为此时能保证a绝对不会下降。
#include<map>#include<set>#include<cmath>#include<ctime>#include<stack>#include<queue>#include<cstdio>#include<cctype>#include<string>#include<vector>#include<cstring>#include<iomanip>#include<iostream>#include<algorithm>#include<functional>#define fuck(x) cout<<"["<<x<<"]"#define FIN freopen("input.txt","r",stdin)#define FOUT freopen("output.txt","w+",stdout)using namespace std;typedef long long LL;typedef pair<int, int>PII;const int MX = 1e5 + 5;const int mod = 1e9 + 7;const LL INF = 0x3f3f3f3f3f3f3f3f;struct Data { LL a, b; bool operator<(const Data &P)const { return a < P.a; } void read(int r, int w) { int x, y; scanf("%d%d", &x, &y); a = (LL)x * r + y; b = (LL)(w - x) * r + y; }} A[MX];LL d[MX];int main() { int n, r, w, h; //FIN; while(~scanf("%d%d%d%d", &n, &r, &w, &h)) { memset(d, INF, sizeof(d)); for(int i = 1; i <= n; i++) { A[i].read(r, w); } sort(A + 1, A + 1 + n); int ans = 0; for(int i = 1; i <= n; i++) { int id = upper_bound(d + 1, d + 1 + n, A[i].b) - d; ans = max(ans, id); d[id] = A[i].b; } printf("%d\n", ans); } return 0;}
0 0
- 二维LIS Gym100820G Racing Gems
- Gym100820G/UVALive7374 Racing Gems 二维LIS 思维题
- Gym-100820 Racing Gems(二维LIS)
- gym 100820G Racing Gems(二维LIS,好题)
- GYM 100820 G.Racing Gems(LIS)
- Racing Gems
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)G】【坐标轴变换 LIS】Racing Gems 开车吃宝石,横向速度不能超
- UVALive 7374 Racing Gems (最长上升子序列--二分法)
- UVALive 7374 Racing Gems - dp,最长上升子序列
- jdfz-2764 二维LIS
- UVALive-7374-Racing Gems(最长上升子序列O(n*logn))
- SGU 199. Beautiful People 二维LIS
- acd - 1216 - Beautiful People(二维LIS)
- 二维无序LIS ACdream1216 Beautiful People
- POJ1609 二维数组快排+LIS
- hdu1069 Monkey and Banana(二维LIS)
- ZOJ 2319 (二维的LIS)
- HDU 6199 gems gems gems
- CrazyFlie源码学习2-Stabilizer任务
- android适配
- LLVM
- java_67---67,68没有看,pass
- CompletableFuture(二)
- 二维LIS Gym100820G Racing Gems
- P25 (*) Generate a random permutation of the elements of a list.
- [Leetcode] 98. Validate Binary Search Tree @python
- 模版方法模式
- 2015年第六届蓝桥杯C/C++程序设计本科B组省赛 牌型种数(结果填空)
- js的作用域学习笔记
- android Http通信局域网测试详解
- Ubuntu12.04安装中文输入法
- 快慢指针------Linked List Cycle