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. iframe 自适应高度和宽度

    <iframe src="pay/index.aspx" marginheight="0" marginwidth="0" frame ...

  2. NVIDIA GRID 和 NICE DCV 技术用于实现 Linux 和 Windows® 图形加速虚拟桌面

    NVIDIA GRID 和 NICE DCV 技术用于实现 Linux 和 Windows® 图形加速虚拟桌面. NICE DCV: 满足 LINUX 和 WINDOWS 的远程 3D 通过 NICE ...

  3. 使用Dump转储文件排查线上环境服务未知问题

    利用Dump转储文件获取正式环境程序堆栈状态 服务异常找不到原因时,我们通常通过重新启动服务来尝试解决问题,但是在决定重启之前,请不要立刻重启Windows服务或站点 重启服务会让当前案发现场的内存证 ...

  4. 继承extends、super、this、方法重写overiding、final、代码块_DAY08

    1:Math类的随机数(掌握) 类名调用静态方法.  包:java.lang 类:Math 方法:public static double random(): Java.lang包下的类是不用导包就可 ...

  5. node.js的

    node.js入门 http://www.cnblogs.com/rubylouvre/archive/2010/07/15/1778403.html 专题:Node.js专区http://devel ...

  6. Spring Boot 基础概述与相关约定配置

    今天打算整理一下 Spring Boot 的基础篇,这系列的文章是我业余时间来写的,起源于之前对微服务比较感兴趣,微服务的范畴比较广包括服务治理.负载均衡.断路器.配置中心.API网关等,还需要结合 ...

  7. OpenKM6.2.5的安装和配置详细过程(附启动失败原因)

    继上文“解决OpenKM启动失败的详细历程”过后,这几天一直在使用OpenKM,OpenKM使用起来很简单,但是一些相关配置什么的中文资料较少,且有的资料欠缺正确性,存在误导性,下面就简单将配置过程和 ...

  8. 谈谈Windows Wow64

    欢迎转载,转载请注明出处:http://www.cnblogs.com/lanrenxinxin/p/4977488.html 本文是<深入理解Windows操作系统 (第六版) >关于6 ...

  9. 【杂谈】从CGI到Servlet

    访问服务器的静态页面 每个Web服务器都运行着一个HTTP服务软件,用于响应web浏览器的请求,返回客户想要的页面.HTTP服务器都会有一个文件夹用于放置相关的页面文件,默认是  /user/loca ...

  10. 白话js this指向问题

    前言   通过本文,你大概能了解this基础指向的问题,抛开例子去说this太虚幻,这里还是结合几篇博文做个整理,算是个人的记录了. 先说概念,this指向与申明无关,永远指向距离自己最近的最终调用者 ...