array array array

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 114    Accepted Submission(s): 65

Problem Description

One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo's path to escape from the museum. But Kiddo didn't want to give it back. So, Kiddo asked Conan a question. If Conan could give a right answer, Kiddo would return the ring to the museum. 
Kiddo: "I have an array A and a number k, if you can choose exactly k elements from A and erase them, then the remaining array is in non-increasing order or non-decreasing order, we say A is a magic array. Now I want you to tell me whether A is a magic array. " Conan: "emmmmm..." Now, Conan seems to be in trouble, can you help him?
 

Input

The first line contains an integer T indicating the total number of test cases. Each test case starts with two integers n and k in one line, then one line with n integers: A1,A2…An.
1≤T≤20
1≤n≤105
0≤k≤n
1≤Ai≤105
 

Output

For 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.
 

Source

 
 //2017-09-10
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ;
int arr[N], rarr[N], n, k;
int dp1[N], dp2[N]; int Search(int* dp,int len,int num){
int low = ,high = len;
while(low <= high){
int mid = (low + high) >> ;
if (num == dp[mid]) return mid;
if (dp[mid] < num) low = mid + ;
else high = mid - ;
}
return low;
} int main()
{
int T;
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &k);
for(int i = ; i <= n; i++)
scanf("%d", &arr[i]);
for(int i = ; i <= n; i++)
rarr[i] = arr[n-i+];
int lis = ;
dp1[] = -;
dp1[] = arr[];
for(int i = ; i <= n; i++){
if(arr[i] > dp1[lis])
dp1[++lis] = arr[i];
else{
int pos = Search(dp1, lis, arr[i]);
dp1[pos] = arr[i];
}
}
int lds = ;
dp2[] = -;
dp2[] = rarr[];
for(int i = ; i <= n; i++){
if(rarr[i] > dp2[lds])
dp2[++lds] = rarr[i];
else{
int pos = Search(dp2, lds, rarr[i]);
dp2[pos] = rarr[i];
}
}
//printf("%d %d\n", lis, lds);
if(n-k <= lis || n-k <= lds)
printf("A is a magic array.\n");
else
printf("A is not a magic array.\n");
} return ;
}

HDU6197的更多相关文章

  1. 【部分转载】:【lower_bound、upperbound讲解、二分查找、最长上升子序列(LIS)、最长下降子序列模版】

    二分 lower_bound lower_bound()在一个区间内进行二分查找,返回第一个大于等于目标值的位置(地址) upper_bound upper_bound()与lower_bound() ...

随机推荐

  1. 基于GTK+3 开发远程控制管理软件(C语言实现)系列二 Centos7下开发环境搭建

    一.安装gcc gcc-c++ make等编译工具 yum install gcc gcc-c++ kernel-devel 这一步,其实可以不用做,你在安装Centos7的时候,如果选择开发模式安装 ...

  2. Python:抓取百度SERP搜索结果页的网站标题信息

    比如,你想采集标题中包含“58同城”的SERP结果,并过滤包含有“北京”或“厦门”等结果数据. 该Python脚本主要是实现以上功能. 其中,使用BeautifulSoup来解析HTML,可以参考我的 ...

  3. Redis笔记(4)独立功能的实现

    1.前言 本节记录一下redis的一些功能上的实现,包括发布订阅.事务.Lua脚本.排序.二进制位数组.慢查询日志和监视器. 2.发布订阅 上一章介绍sentinel的时候说到了sentinel会订阅 ...

  4. ring3下的IAT HOOK

    标 题: [原创]ring3下的IAT HOOK作 者: hostzhen时 间: 2013-03-28,11:30:53链 接: http://bbs.pediy.com/showthread.ph ...

  5. 数据库设计 Step by Step (1)——扬帆启航

    引言:一直在从事数据库开发和设计工作,也看了一些书籍,算是略有心得.很久之前就想针 对关系数据库设计进行整理.总结,但因为种种原因迟迟没有动手,主要还是惰性使然.今天也算是痛下决心开始这项卓绝又令我兴 ...

  6. 常用的Maven 插件

    Maven本质上是一个插件框架,它的核心并不执行任何具体的构建任务,所有这些任务都交给插件来完成. 例如编译源代码是由maven- compiler-plugin完成的.进一步说,每个任务对应了一个插 ...

  7. SSM整合——spring4.*配置案例

    导入spring4.* 相关的jar包和依赖包即可 1.web.xml <?xml version="1.0" encoding="UTF-8"?> ...

  8. java实现跳跃表

    先贴上一个MIT跳跃表公开课链接:http://open.163.com/movie/2010/12/7/S/M6UTT5U0I_M6V2TTJ7S.html redis中的有序链表结构就是在跳跃表的 ...

  9. 【IT笔试面试题整理】二叉搜索树转换为双向链表

    [试题描述] 将二叉搜索树转换为双向链表 对于二叉搜索树,可以将其转换为双向链表,其中,节点的左子树指针在链表中指向前一个节点,右子树指针在链表中指向后一个节点. 思路一: 采用递归思想,对于二叉搜索 ...

  10. Mybatis插件使用-统计sql执行时间

    背景介绍:最近由于产品数据量较大,sql执行十分低效,正在做数据库优化,所以想在日志中看到每个sql执行的时间,以方便针对性的优化. 查找相关资料,了解到Mybatis有一款插件,是基于interce ...