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. Python 关于 encode与decode 中文乱码问题

    字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(en ...

  2. Git-管理和撤销修改

    一.管理修改 为什么说Git管理的是修改,而不是文件呢?我们还是做实验.第一步,对readme.txt做一个修改,比如加一行内容: Git is a distributed version contr ...

  3. activemq在一台服务器上启动多个Broker

    步骤如下: 1.把整个conf文件夹复制一份,比如叫conf2 2.修改里面的activemq.xml文件 ①brokerName不能和原来的重复 ②数据存放的文件名称不能重复,比如<kahaD ...

  4. 不能将 CHECK_POLICY 和 CHECK_EXPIRATION 选项设为 OFF (关)

    数据库用户信息死活无法修改..老是出现错误当 MUST_CHANGE 为 ON (开)时,不能将 CHECK_POLICY 和 CHECK_EXPIRATION 选项设为 OFF (关). (Micr ...

  5. 通过修改CR0寄存器绕过SSDT驱动保护

    为了安全起见,Windows XP及其以后的系统将一些重要的内存页设置为只读属性,这样就算有权力访问该表也不能随意对其修改,例如SSDT.IDT等.但这种方法很容易被绕过,我们只要将这些部分修改为可写 ...

  6. Window服务与Quartz.NET

    Quartz.NET: http://quartznet.sourceforge.net/ (现为2.2版本) Sourceforge:http://sourceforge.net/projects/ ...

  7. Android 开发工具类 36_ getSimSerial

    1 /** * 获取手机的 sim 卡串号 * 需要在清单文件中配置权限: * <uses-permission android:name="android.permission.RE ...

  8. win2003 远程连接限制

    1.单击开始->运行,输入gpedit.msc,打开组策略编辑器,找到计算机配置 ->管理模版 -> Windows组件 ->终端服务.把限制连接数量的属性修改成我们需要的数字 ...

  9. tensorflow 在同一个GPU同时加载多张相同的图

    saver = self.tf_instance.train.Saver() self.sess = self.tf_instance.Session(config=sess_config, grap ...

  10. 深入理解java中HelloWorld的执行流程

    HelloWorld.java是我们学习java的第一个程序,简单的再也不能简单了,可是里面的原理以及执行流程大家都知道吗?最近在复习java知识,特地钻研了一番分享给大家! 贴出HelloWorld ...