array array array

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

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
 
这道题转换之后就是求最长上升子序列长度,此外,发现了一种二分求LIS方法。
 
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<string>
#define LL long long
const int maxn=1e5+5;
using namespace std;
int a[maxn],b[maxn],c[maxn];
int n;
int LIS(int *d){
memset(c,0,sizeof(c));
c[1]=d[1];
int l,r,mid,len=1;
for(int i=2;i<=n;i++){
l=1;
r=len;
while(l<=r){
mid=(l+r)/2;
if(c[mid]<=d[i]) l=mid+1;
else r=mid-1;
}
c[l]=d[i];
if(l>len) len++; }
return len;
}
int main()
{
int T;
scanf("%d",&T);
int k;
while(T--)
{
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=-a[i];
}
int maxn=max(LIS(a),LIS(b)); if(n-maxn>k)
printf("A is not a magic array.\n");
else
printf("A is a magic array.\n");
}
return 0;
}

  

hdu 6197 array array array的更多相关文章

  1. hdu 6197 2017 ACM/ICPC Asia Regional Shenyang Online array array array【最长不上升子序列和最长不下降子序列】

    hdu 6197 题意:给定一个数组,问删掉k个字符后数组是否能不减或者不增,满足要求则是magic array,否则不是. 题解:队友想的思路,感觉非常棒!既然删掉k个后不增或者不减,那么就先求数组 ...

  2. LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>

    LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...

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

  4. Array.fill & array padding

    Array.fill & array padding arr.fill(value[, start[, end]]) https://developer.mozilla.org/en-US/d ...

  5. HDU 6197 array array array 2017沈阳网络赛 LIS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增 ...

  6. HDU - 6197:array array array (简单LIS)

    One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo's path ...

  7. hdu 6197 array array array LIS

    正反跑一次LIS,取最大的长度,如果长度大于n-k就满足条件. ac代码: #include <cstdio> #include <cstring> #include < ...

  8. HDU - 6197 array array array (最长上升子序列&最长下降子序列)

    题意:对于一个序列,要求去掉正好K个数字,若能使其成为不上升子序列或不下降子序列,则“A is a magic array.”,否则"A is not a magic array.\n&qu ...

  9. hdu 5280 Senior's Array

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...

随机推荐

  1. 如何在GitHub上生成ssh公钥并用NetBeans克隆项目

    一.生成ssh公钥. 1.首先判断本机是否创建了公有密钥: $ ls ~/.ssh 这个命令用于检查是否已经存在 id_rsa.pub 或 id_dsa.pub 文件,如果文件已经存在,下面步骤可省略 ...

  2. 再起航,我的学习笔记之JavaScript设计模式11(外观模式)

    经过一段时间的学习与分享,我们对创建型设计模式已经有了一定的认识,未来的一段时间里我们将展开新的篇章,开始迈入结构性设计模式的学习. 结构性设计模式与创建型设计模式不同,结构性设计模式更偏向于关注如何 ...

  3. 在配置wem.xml后,Tomcat遇到问题,启动失败的解决方法

    前两天在写程序时,碰到了Tomcat无法启动的问题,就是在配置完web.xml后.想必好多小伙伴都有遇到吧. 如图: 出现这个错误的原因是:在配置web.xml的时候出现了错误! 如图所示,没有修改这 ...

  4. go web 第三天 学习笔记 --mysql

    CREATE TABLE `userinfo` ( `uid` INT() NOT NULL AUTO_INCREMENT, `username` VARCHAR() NULL DEFAULT NUL ...

  5. 匿名委托与Lambda表达式

    通过使用匿名委托(匿名方法),使编程变得更加灵活,有关委托与匿名委托请参考我的前一篇Blog<委托与匿名委托>. 继续之前示例,代码如下: static void Main(string[ ...

  6. Python之测试webservice接口

    前段时间学习了Python操作http接口,觉得挺容易的.最近项目组也有接触webservice接口,心里想想是否Python也可以操作这类接口.于是利用伟大的度娘,花了6个小时研究出来了,所以迫不及 ...

  7. jsp的C标签一般使用方法以及js接收servlet中的对象及对象数字

    jsp的C标签一般使用方法以及js接收servlet中的对象及对象数组 由于现流行的javaWeb框架提倡前后端分离,比如在SpringMvc中已经很少写servlet的一些东西:目前 前端jsp中大 ...

  8. Django编写RESTful API(六):ViewSets和Routers

    欢迎访问我的个人网站:www.comingnext.cn 前言 在本系列的文章中,我在第一篇和第二篇文章中写的编写Django视图时,使用的都是基于函数的方法,并且每个视图函数之前都会加一个djang ...

  9. java面向对象理解

    面向对象:世间一切事物均可认为是对象,用户不必了解软件内部的实现机制,可根据需要直接调用接口,生成一个正常工作的应用程序. 面向对象的特点:抽象,封装,继承,多态性, 对象:对象就是一个具有明确行为的 ...

  10. 带你走进SAP项目实施过程——立项(1)

    到底谁会首先有上ERP的想法,可能是企业老板,也可能是总经理级别等高管.但不管是谁,在确定之前,按道理企业风控部.总经办或者信息部等相关部门都需要对ERP项目做立项申请.毕竟ERP项目涉及企业方方面面 ...