hdu 6197 array array array
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
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?
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
4 1
1 4 3 7
5 2
4 1 3 1 2
6 1
1 4 3 5 4 6
A is a magic array.
A is not a magic array.
#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的更多相关文章
- hdu 6197 2017 ACM/ICPC Asia Regional Shenyang Online array array array【最长不上升子序列和最长不下降子序列】
hdu 6197 题意:给定一个数组,问删掉k个字符后数组是否能不减或者不增,满足要求则是magic array,否则不是. 题解:队友想的思路,感觉非常棒!既然删掉k个后不增或者不减,那么就先求数组 ...
- LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>
LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...
- 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 ...
- Array.fill & array padding
Array.fill & array padding arr.fill(value[, start[, end]]) https://developer.mozilla.org/en-US/d ...
- HDU 6197 array array array 2017沈阳网络赛 LIS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增 ...
- HDU - 6197:array array array (简单LIS)
One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo's path ...
- hdu 6197 array array array LIS
正反跑一次LIS,取最大的长度,如果长度大于n-k就满足条件. ac代码: #include <cstdio> #include <cstring> #include < ...
- HDU - 6197 array array array (最长上升子序列&最长下降子序列)
题意:对于一个序列,要求去掉正好K个数字,若能使其成为不上升子序列或不下降子序列,则“A is a magic array.”,否则"A is not a magic array.\n&qu ...
- hdu 5280 Senior's Array
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...
随机推荐
- .net到Java那些事儿--整合SSH
一.介绍 整体介绍分成两个部分,第一.net转到Java的原因,第二开发SSH时候的环境介绍: .net到Java的原因: .net开发也将近快3年的样子,加上现在的老东家换过 ...
- koa2 controller中实现类似sleep的延迟功能
今天有同事问我如何在koa2中的controller中使用延迟执行的功能,他直接在controller中使用setTimeout,但是没效果. 错误的代码类似下面这样: // 错误的方法 export ...
- Fedora25和win10双系统安装及使问题汇总
安装问题汇总 1.U盘引导制作后,开机出现":Assuming driver cache: write through" 解决方案:经过排查后,怀疑是U盘启动制作出了问题,后来查阅 ...
- 20个开发人员非常有用的Java功能代码
本文将为大家介绍20个对开发人员非常有用的Java功能代码.这20段代码,可以成为大家在今后的开发过程中,Java编程手册的重要部分. 1. 把Strings转换成int和把int转换成String ...
- 【Ubuntu 16】网络配置文件
之前使用图形化NetworkManager配置静态IP,但在/etc/network/interfaces中找不到静态IP的配置信息,让人不解. 今天在网上看到网友的一则文章,知道了在/etc/Net ...
- 跨server传输数据注意事项
我们需要模拟客服端 首先导入相关的jar包 文件,Jersey的相关jar包 实现客服端的代码为: @Test public void testClient() { //图片生成 ...
- Sql Server数据库使用触发器和sqlbulkcopy大批量数据插入更新
需要了解的知识 1.触发器 2.sqlbulkcopy 我的用途 开发数据库同步的工具,需要大批量数据插入和数据更新. 方式 使用SqlBulkCopy类对数据进行数据批量复制,将需要同步数据的表新建 ...
- Cell
首先需要创建一个model类,继承于NSObject: 定义两个属性: @property(nonatomic,retain)NSString imageName; @property(nonatom ...
- hdu 5040 Instrusive
Instrusive Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Tota ...
- 扩展Python模块系列(五)----异常和错误处理
在上一节中,讨论了在用C语言扩展Python模块时,应该如何处理无处不在的引用计数问题.重点关注的是在实现一个C Python的函数时,对于一个PyObject对象,何时调用Py_INCREF和Py_ ...