hdu 6197 array array array

http://acm.hdu.edu.cn/showproblem.php?pid=6197

题意:给你一个数组 然后给你一个k  让你从数组里面剔除k个数  使得剩余的数组 是 单调非递减  或 单调非递增的

判断可不可能

思路 : 直接写LIS  然后判断 n-k 和 LIS 长度的大小关系

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+100;
const int INF = 0x3f3f3f3f;
int n,m;
int s[maxn];
int cnt[maxn];

int main ()
{
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--){
        cin >> n >> m;
        for(int i=1;i<=n;i++)
            cin >> s[i];
        fill(cnt,cnt+n,INF);
        for(int i=1;i<=n;i++)
        {
            *upper_bound(cnt,cnt+n,s[i]) = s[i];
        }
        int len1 = lower_bound(cnt,cnt+n,INF) - cnt;
        fill(cnt,cnt+n,INF);
        for(int i=n;i>=1;i--)
        {
            *upper_bound(cnt,cnt+n,s[i]) = s[i];
        }
        int len2 = lower_bound(cnt,cnt+n,INF) - cnt;
        int ans = max(len1,len2);
        if(n-m > ans)
            puts("A is not a magic array.");
        else
            puts("A is a magic array.");
    }
}
时间: 2024-08-06 07:18:02

hdu 6197 array array array的相关文章

hdu 5280 Senior&#39;s Array

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie gets an array $A$. Among all non-empty intervals of $A$, she wants to find the most beautiful one. She defines the beauty as the sum of the interval. Th

hdu 5280 Senior&#39;s Array(最大子段和)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5280 题意:将一个长度为n的数组,将里面某一个数改为p,使改变后最大子段和最大. 题解:dp[i]=max(dp[i-1)+a[i],a[i]),表示以第 i 个数结束的最大子段和,时间复杂度为O(n). 1)由于n<=1000,可以暴力解决,将每一个数都依次改为p,求出最大的子段和,再去这些最大子段和中最大的,时间复杂度为O(n*n); #include <iostream> #inclu

HDU 5280 Senior&#39;s Array (暴力,水)

题意:给一个数列,再给一个数字p,要求p一定要替换掉数列中的一个元素,然后求最大连续子序列之和. 思路:1000*1000的复杂度,O(n*n) .就是每个都试,然后求和. 1 #include <bits/stdc++.h> 2 #define LL long long 3 #define pii pair<int,int> 4 #define INF 0x7f7f7f7f 5 using namespace std; 6 const int N=2000; 7 int a[N]

[最大子序列和]Hdu 5280 Senior&#39;s Array

题意:一个序列,在其中一个数必须替换成给定数字p的条件下,求最大连续子序列之和. 依次把每一个数替换成p,求每次的最大连续和,找出最大值.O(n^2). #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> typedef long long ll; using namespace std; const int MAXN=1000+5; const int

hdu 5164 Matching on Array (用map实现的ac自动机)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5164 题意: 给出长度为n一个母串,给出m个长度为ki子串,匹配的条件是比率相同,如子串4 8 能和 1 2 4匹配.问所有子串在母串中出现多少次. 限制: 1 <= n,m <= 1e5 1 <= ki <= 300000 思路: 赤裸裸的ac自动机啊,不过next数组用map来实现,出题人脑洞真大. 这里有一点还要注意,hdu的g++,结构体里面不能开太大的东西,要不然他ce了还

HDU 5280 Senior&#39;s Array 最大区间和

题意:给定n个数,要求必须将其中某个数改为P,求改动后最大的区间和可以为多少. 水题.枚举每个区间,如果该区间不修改(即修改该区间以外的数),则就为该区间和,若该区间要修改,因为必须修改,所以肯定是把最小的数修改为P能保证该区间最后和最大,所以比较两种方案的较大者.对于每个区间取出的较大者,再取总共的最大者即可.注意一个trick,枚举到整个区间的时候,是必须要修改一个数的,所以这个最大的这个区间只有一种方案.先预处理1~i的区间和,维护每个区间的最小值和区间和. #include <iostr

[C++] the pointer array &amp; the array&#39;s pointer

void main(){ // the pointer array char* arry[] = { "hello", "world", "haha" }; for (int i = 0; i < 3; i++){ printf("string:%s,address:%p\n", arry[i], arry[i]); } // the array's pointer int a[10] = { 0, 1, 2, 3, 4

theme(&#39;item-list&#39;,array(&#39;items&#39;=&gt;array(&#39;aaa&#39;,&#39;bbb&#39;))) 是如何运行的 ?

$items['items'] = array( l('Configure', 'admin/config'), l('Structure', 'admin/structure'), ); $theme = theme('item_list', $items); 1,  判断是否所有的模块都加载了, if (!module_load_all(NULL) && !defined('MAINTENANCE_MODE')) { throw new Exception(t('theme() may

JavaScript定义数组的三种方式(new Array(),new Array(&#39;x&#39;,&#39;y&#39;),[&#39;x&#39;,&#39;y&#39;])

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

Linux Array & Associative Array

Ordinary Array: Assign1: arrayName=(value1 value2 ...) Assign2: arrayName[index]=value Length: ${#arrayName[*]} or ${#arrayName[@]} Indexes: ${!arrayName[*]} or ${#arrayName[@]} Example: #!/bin/bash group1=(rio amos) group2[0]=bill group2[1]=frank gr