您的位置:首页 > 其它

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 :这个思维还是很难想到的

#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;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: