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. Swift5 语言参考(二) 词法结构

    词汇结构 Swift 的词法结构描述了什么样的字符序列形成了语言的有效标记.这些有效令牌构成语言的最低级构建块,用于描述后续章节中的其余语言.令牌由标识符,关键字,标点符号,文字或运算符组成. 在大多 ...

  2. Linux 下创建 sftp 用户并限定目录

    Linux 下创建 sftp 用户并限定目录 1.创建 sftpUser 用户组 [root@XXX ~]# groupadd sftpUser 2.创建 sftpUser 用户并指定目录 [root ...

  3. JQuery 限制文本输入只能输入数字(可自定义正则表达式)

    var JVerify = { role: { number: /[0-9\/]/, decimal: /[0-9\.\/]/, code: /[0-9A-Z]/ }, Verify: functio ...

  4. d3.js在vue项目中的安装及案例

    1. 安装: npm i d3 --save 2. 引入:main.js import * as d3 from "d3"; Vue.prototype.$d3 = d3; win ...

  5. vs2017 对dockerfile的支持

    项目添加 dockerfile Docker file 内容 FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base WORKDIR /app EXP ...

  6. 剑指offer十四之链表中倒数第k个结点

    一.题目 输入一个链表,输出该链表中倒数第k个结点. 二.思路 两个指针,先让第一个指针和第二个指针都指向头结点,然后再让第一个指正走(k-1)步,到达第k个节点.然后两个指针同时往后移动,当第一个结 ...

  7. 解决chkconfig设置开机启动时出现missing LSB的错误

    0x00 主要原因是脚本不符合LSB tags规范,在#!/bin/bash下面添加如下代码即可 以tomcat为例 ### BEGIN INIT INFO # Provides: bbzhh.com ...

  8. windwos平台安装phpredis模块

    要求 必备知识 熟悉基本编程环境搭建. 运行环境 windows 7(64位);php-5.3 redis64-2.8.17 下载地址 环境下载 什么是PHP Redis PHP Redis 是一个用 ...

  9. Spring Security OAuth2实现单点登录

    1.概述 在本教程中,我们将讨论如何使用 Spring Security OAuth 和 Spring Boot 实现 SSO(单点登录). 本示例将使用到三个独立应用 一个授权服务器(中央认证机制) ...

  10. Ajax初始接触

    演示JS对象的属性,方法和事件的使用 (1)window.location.href (2)form.submit() <form action="" method=&quo ...