HDU - 6197:array array array (简单LIS)
Kiddo: "I have an array A A
and a number k k
, if you can choose exactly k k
elements from A A
and erase them, then the remaining array is in non-increasing order or non-decreasing order, we say A A
is a magic array. Now I want you to tell me whether A A
is a magic array. " Conan: "emmmmm..." Now, Conan seems to be in trouble, can you help him?
InputThe first line contains an integer T indicating the total number of test cases. Each test case starts with two integers n n
and k k
in one line, then one line with n n
integers: A 1 ,A 2 …A n A1,A2…An
.
1≤T≤20 1≤T≤20
1≤n≤10 5 1≤n≤105
0≤k≤n 0≤k≤n
1≤A i ≤10 5 1≤Ai≤105
OutputFor each test case, please output "A is a magic array." if it is a magic array. Otherwise, output "A is not a magic array." (without quotes).
Sample Input
3
4 1
1 4 3 7
5 2
4 1 3 1 2
6 1
1 4 3 5 4 6
Sample Output
A is a magic array.
A is a magic array.
A is not a magic array.
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int a[maxn],b[maxn];
int main()
{
int T,N,K,cnt,pos;
scanf("%d",&T);
while(T--){
scanf("%d%d",&N,&K);
rep(i,,N) scanf("%d",&a[i]);
cnt=;
rep(i,,N) pos=upper_bound(b+,b+cnt+,a[i])-b,b[pos]=a[i],cnt=max(pos,cnt);
if(cnt+K>=N) puts("A is a magic array.");
else {
reverse(a+,a+N+);
cnt=;
rep(i,,N) pos=upper_bound(b+,b+cnt+,a[i])-b,b[pos]=a[i],cnt=max(pos,cnt);
if(cnt+K>=N) puts("A is a magic array.");
else puts("A is not a magic array.");
}
}
return ;
}
HDU - 6197:array array array (简单LIS)的更多相关文章
- hdu 6197 2017 ACM/ICPC Asia Regional Shenyang Online array array array【最长不上升子序列和最长不下降子序列】
hdu 6197 题意:给定一个数组,问删掉k个字符后数组是否能不减或者不增,满足要求则是magic array,否则不是. 题解:队友想的思路,感觉非常棒!既然删掉k个后不增或者不减,那么就先求数组 ...
- Array.fill & array padding
Array.fill & array padding arr.fill(value[, start[, end]]) https://developer.mozilla.org/en-US/d ...
- LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>
LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...
- js Array.from & Array.of All In One
js Array.from & Array.of All In One 数组生成器 Array.from The Array.from() static method creates a ne ...
- HDU 6197 array array array 2017沈阳网络赛 LIS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增 ...
- hdu 6197 array array array LIS
正反跑一次LIS,取最大的长度,如果长度大于n-k就满足条件. ac代码: #include <cstdio> #include <cstring> #include < ...
- hdu 6197 array array array
array array array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU - 6197 array array array (最长上升子序列&最长下降子序列)
题意:对于一个序列,要求去掉正好K个数字,若能使其成为不上升子序列或不下降子序列,则“A is a magic array.”,否则"A is not a magic array.\n&qu ...
- hdu 5280 Senior's Array
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...
随机推荐
- Linux静默安装Oracle
打算在云服务器上装oracle服务,以前DBA美眉都是在图形化界面下安装,这次抓瞎了.赶紧上网查查,静默安装可以解决问题.于是乎赶紧开始部署,过程如下.安装环境:操作系统:CentOS 7内存:11G ...
- Nginx 自定义404、500错误页面跳转
自定义Nginx错误界面跳转 1.开启Nginx.conf配置文件下的自定义接口参数. http { fastcgi_intercept_errors on; } 2.在Server区域添加自定义的错 ...
- Mysql 忘记密码处理配置
Mysql忘记密码处理 1.设置mysql密码 mysqladmin -uroot password ‘密码’ 2.主配置文件下取消密码授权 vim /etc/my.cnf 注:加入skip-gran ...
- 限制goroutine数量写法
虽然golang的goroutine可以开启无数个goroutine,但是没有限制也是不行的.我就写一下我对goroutine数量限制的写法 1.初始化goroutine协程池.把goroutine数 ...
- Java套接字socket编程笔记
相对于C和C++来说,Java中的socket编程是比较简单的,比较多的细节都已经被封装好了,每次创建socket连接只需要知道地址和端口即可. 在了解socket编程之前,我们先来了解一下读写数据的 ...
- Python-GUI编程-PyQt5
Python-GUI编程-PyQt5 1. GUI编程是什么? GUI 全称为: Graphical User Interface;简称GUI翻译为中文为: 图形化用户接口简单理解就是:- 使用Pyt ...
- angularjs Dom方式访问疑似可以访问ifame结构项目
一.定位需要访问控制器元素 var currObj = document.querySelector('[ng-controller="munuListCtrl"]'); 或者 v ...
- JAVA文件下载,页面显示另存为效果
经过测试 firefox.QQ.IE 浏览器是可以的 chrome浏览器不行(直接下载了) 1. 系统框架springmvc+jsp 2. 后台servlet代码 @RequestMapping( ...
- http客户端-基于boost开发
http客户端-基于boost开发 基于BOOST编写的http客户端,作为BOOST开发学习之用.目前支持功能: http协议,单向链接返回http response code 200 可conte ...
- scala学习手记3 - var和val
scala中用var和val定义变量都是可以的. 用val定义的变量是不可变的,被初始化后值就固定下来,不可以再被修改(这类似于java中的final关键字):用var定义的变量是可变的,可以任意修改 ...