2017 ACM/ICPC Asia Regional Shenyang Online array array array

Posted pprp

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017 ACM/ICPC Asia Regional Shenyang Online array array array相关的知识,希望对你有一定的参考价值。

2017-09-15 21:05:41

writer:pprp

给出一个序列问能否去掉k的数之后使得整个序列不是递增也不是递减的
先求出LIS,然后倒序求出最长递减子序列长度,然后判断去k的数后长度是否都大于所求长度
代码如下:
#include <bits/stdc++.h>

using namespace std;

int arr1[100005],tmp1[100005],arr2[100005], tmp2[100005];
int len1,len2;

int main()
{
    int cas;
//    cin >> cas;
    scanf("%d",&cas);
    while(cas--)
    {
        int N, K;
//        cin >> N >> K;
        scanf("%d%d",&N,&K);
        len1=1, len2 = 1;
        for(int i = 0 ; i < N ; i++)
        {
             scanf("%d",&arr1[i]);
        }
        for(int i = N - 1; i >= 0; i--)
        {
            arr2[i] = arr1[N-i];
        }
        tmp1[len1] = arr1[0];
        tmp2[len2] = arr2[0];

        for(int i=1; i<N; i++)
        {
            if(arr1[i] > tmp1[len1])//如果当前i指向的arr的值大于tmp当前的值
            {
                len1++;
                tmp1[len1]=arr1[i];
            }
            else
                *lower_bound(tmp1,tmp1+len1,arr1[i]) = arr1[i];
        }

        for(int i = 1; i < N ; i++)
        {
            if(arr2[i] > tmp2[len2])
            {
                len2++;
                tmp2[len2] = arr2[i];
            }
            else
                *lower_bound(tmp2,tmp2+len2,arr2[i]) = arr2[i];
        }

        int cmp = N - K;
        if(cmp > len1 && cmp > len2)
            cout << "A is not a magic array." << endl;
        else
            cout << "A is a magic array." << endl;
    }
    return 0;
}

 

以上是关于2017 ACM/ICPC Asia Regional Shenyang Online array array array的主要内容,如果未能解决你的问题,请参考以下文章

2017 ACM/ICPC Asia Regional Beijing Online

2017 ACM/ICPC Asia Regional Qingdao Online

2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

HDU 6198(2017 ACM/ICPC Asia Regional Shenyang Online)

HDU - 6215 2017 ACM/ICPC Asia Regional Qingdao Online J - Brute Force Sorting