uvalive 7374(LIS)
2017-10-21 11:06
295 查看
这个题思维性真的强!没想到是对于每一个点弄出它的左右的边界点。
题目大意:
现有一个长为h(竖直方向),宽为w(水平方向)的跑道,跑道上有一些宝石, 给出每一个宝石的坐标。你可以从起点线的任何一个位置(x,0)出发,出发后在竖直方向上有一个恒定的速度v,水平方向上的速度你可以在任意时刻控制在(-v/r~v/r)之间的任何一个值(给出r的值,不给出v的值),当你到达终点线时,移动结束。求你从起点线出发最多可以获得多少宝石。
思路:对于每一个点他能到达的区域就是以这个点开始的两条斜率分别为-r,r的射线形成的区域之上,所以对于每一个点只需要得出它的左右两点(分别为射线与两个x边界相交的点)的高度L,R,如果b点能被a点到达那么就是Lb >= La && Rb >= Ra,所以就是我们可以先按L排序,然后在R 中找一个最长的上升子序列LIS。
盗一张图:(图转自http://blog.csdn.net/xbb224007/article/details/77854353)
PS :这个思维还是很难想到的
题目大意:
现有一个长为h(竖直方向),宽为w(水平方向)的跑道,跑道上有一些宝石, 给出每一个宝石的坐标。你可以从起点线的任何一个位置(x,0)出发,出发后在竖直方向上有一个恒定的速度v,水平方向上的速度你可以在任意时刻控制在(-v/r~v/r)之间的任何一个值(给出r的值,不给出v的值),当你到达终点线时,移动结束。求你从起点线出发最多可以获得多少宝石。
思路:对于每一个点他能到达的区域就是以这个点开始的两条斜率分别为-r,r的射线形成的区域之上,所以对于每一个点只需要得出它的左右两点(分别为射线与两个x边界相交的点)的高度L,R,如果b点能被a点到达那么就是Lb >= La && Rb >= Ra,所以就是我们可以先按L排序,然后在R 中找一个最长的上升子序列LIS。
盗一张图:(图转自http://blog.csdn.net/xbb224007/article/details/77854353)
PS :这个思维还是很难想到的
#include<bits/stdc++.h> using namespace std; #define clr(x,y) memset(x,y,sizeof x) const int maxn = 3e5 + 10; struct Node { bool operator < (Node t) { return x < t.x; } double x,y; }a[maxn],st[maxn]; int get(int l,int r,double x) { int ret; while(l <= r) { int mid = (l + r) >> 1; if(st[mid].y > x)ret = mid,r = mid - 1; else l = mid + 1; } return ret; } int main() { int n; while( ~ scanf("%d",&n)) { double r,w,h;scanf("%lf%lf%lf",&r,&w,&h); for(int i = 1;i <= n;i ++) { double x,y;scanf("%lf%lf",&x,&y); a[i] = (Node){y + x * r,y + (w - x) * r}; } sort(a + 1,a + n + 1); // for(int i = 1; i <= n;i ++)cout << " " << a[i].y << " -- ";puts(""); int cnt = 0;st[++ cnt] = a[1]; for(int i = 2;i <= n;i ++) { if(a[i].y >= st[cnt].y){st[++ cnt] = a[i];continue;} int pos = get(1,cnt,a[i].y); st[pos] = a[i]; } printf("%d\n",cnt); } return 0; }
相关文章推荐
- UVALive - 7374 Racing Gems 二维非递减子序列
- UvaLive 6667 Longest Chain (分治求三维LIS)
- UVALive 7374 Racing Gems (最长上升子序列--二分法)
- UVALive 7374 Racing Gems - dp,最长上升子序列
- UvaLive 6667 Longest Chain (分治求三元组LIS&树状数组)
- UVALive-7374-Racing Gems(最长上升子序列O(n*logn))
- UVALive - 4256 Salesmen(LIS变形)
- UVA 10635 Prince and Princess LCS转化为LIS *
- UVALive - 6582 Magical GCD (脑洞)
- UVALive - 3938:"Ray, Pass me the dishes!"
- C - Cent Savings UVALive - 6952
- UVALive-6955
- uvalive 6393(uva 1572) Self-Assembly 拓扑排序
- UVALive - 3401 Colored Cubes
- UVALive 4329 Ping pong(解法二:树状数组)
- UVALive 4639 - Separate Points
- UVaLIve 2889 | LA 2889 | UVa 12050 - Palindrome Numbers (组合数学)
- UVALive 7962|Gym 101201K|Tournament Wins|概率期望|组合数求对数
- UVALive 3713 Astronauts
- UVA live - 4327(滑动队列优化dp)