首先这题目真心难懂,其实并不复杂,但是学会了lower_bound(),用法lower_bound(数组名,数组名+数组元素个数,要找的值)-数组名,注意数列必须本来有序,返回值是小于该值的最大的那个数的下一个坐标,即有许多并列的那个数,比如1,2,3,3,3,4要找3,则输出2
dp(i)代表从左边开始第i个灯塔,不考虑右边的的影响,能存活的灯塔数。
#include
#include
struct node
{
int postion;
int power;
};
node a[100005];
int dp[100005];
int b[100005];
using namespace std;
int cmp(node x,node y)
{
return x.postion>n;
for (i=0;i>a[i].postion>>a[i].power;
sort(a,a+n,cmp);//根据坐标从小达到排序
dp[0]=1;
ans=1;//注意可能n=1
for (i=0;ians)
ans=dp[i];
}
cout<