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 ...
随机推荐
- IE6/7 下:inline-block解决方案
6/IE7下:inline-block解决方案 IE6/IE7下对display:inline-block的支持性不好. 1.inline元素的display属性设置为inline-block时, ...
- Java应对Flash XSS攻击
问题引出: 今天公司派出安全任务,说是要解决一个Flash XSS攻击,一看顿时傻眼,都没听说过.而且flash已经淘汰了,根本没研究过flash,搜了资料才开始慢慢开始工作. 要求: 1.过滤URL ...
- 强大的jQuery幻灯片播放插件 支持全拼、拖拽和下载等功能
在线演示 本地下载
- 让Tomcat供外网访问
使用Tomcat+花生壳部署一个Javaweb网站,步骤分为三步. 第一,花生壳配置. 下载花生壳,并默认安装.申请动态域名,激活护照,登录.(都是常规操作,不必多说) 第二,Tomcat设置. 找到 ...
- JUnit4 入门笔记
Test注解的两个可选参数 expected timeout The Test annotation supports two optional parameters. The first, expe ...
- Python 私有化属性
# 对象的基本理论 # 什么事对象? # 万物皆对象 # 对象是具体物体 # 拥有属性 # 拥有行为 # 把很多零散的东西,封装成为一个整体 # 举例:王二小 # 属性 # 姓名 # 年龄 # 身高 ...
- Latex排版全解【转载】
Latex排版全解 https://www.cnblogs.com/jingwhale/p/4250296.html
- C#与C++之间类型对应关系
//C++中的DLL函数原型为 //extern "C" __declspec(dllexport) bool 方法名一(const char* 变量名1, unsigned c ...
- Linux 实用指令之查看端口开启情况
netstat -ntlp 查看端口使用情况! netstat -ntlp | grep 80 查看具体的端口是否使用! # netstat -ntlp Active Internet connect ...
- python学习笔记(pip下载安装)
python有很多扩展模块需要安装 这个时候万能的pip就可以提供帮助 首页进入官网下载压缩包: https://pypi.python.org/pypi/pip#downloads 解压文件 cmd ...