NOIP 拦截导弹

题目链接:https://www.luogu.org/problemnew/show/P1020
题意很简洁,一共两问。
第一问是求单个拦截系统最多能拦截多少个,根据题意即最长非上升子序列。
第二问有多少导弹拦截系统才能拦截全部导弹,即有多少最长非上升子序列才能包括全部数。
稍加思考即可得出最长上升子序列的长度即为答案。
本题的转化思考和两个求序列长度写法要记一下(就我目前看到的题解貌似没人这么写。。。)。

#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long int
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
const int inf = 0x3f3f3f3f;
int s[100100];
int up[100100];
int down[100100];
int main()
{
    int cmp = 0;
    memset(up, inf, sizeof(up));
    memset(down, inf, sizeof(down));
    while (~scanf("%d", &s[cmp++])); cmp--;
    for (int i =cmp-1;i>=0;i--)
        *upper_bound(down, down + cmp, s[i]) = s[i];
    for (int i = 0; i < cmp; i++)
        *lower_bound(up, up + cmp, s[i]) = s[i];
    int res = lower_bound(down, down + cmp, inf) - down;
    int ans = lower_bound(up, up + cmp, inf) - up;
    cout << res << endl;
    cout << ans << endl;
    //system("pause");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值