HDU6197
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
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
1≤T≤20
1≤n≤105
0≤k≤n
1≤Ai≤105
Output
Sample Input
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 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的更多相关文章
- 【部分转载】:【lower_bound、upperbound讲解、二分查找、最长上升子序列(LIS)、最长下降子序列模版】
二分 lower_bound lower_bound()在一个区间内进行二分查找,返回第一个大于等于目标值的位置(地址) upper_bound upper_bound()与lower_bound() ...
随机推荐
- Elasticsearch重要文章之四:监控每个节点(ThreadPool部分)
http://zhaoyanblog.com/archives/754.html ThreadPool部分 Elasticsearch 内部使用了线程池,通过这些线程池之间的合作完成工作,在需要时传递 ...
- Akka(20): Stream:异步运算,压力缓冲-Async, batching backpressure and buffering
akka-stream原则上是一种推式(push-model)的数据流.push-model和pull-model的区别在于它们解决问题倾向性:push模式面向高效的数据流下游(fast-downst ...
- 动态分析小示例| 08CMS SQL 注入分析
i春秋作家:yanzm 0×00 背景 本周,拿到一个源码素材是08cms的,这个源码在官网中没有开源下载,需要进行购买,由某师傅提供的,审计的时候发现这个CMS数据传递比较复杂,使用静态分析的方式不 ...
- zookeeper的安装与配置(单机和集群)
单机模式: 1.首先去官网下载zookeeper的包 zookeeper-3.4.10.tar.gz 2.用FTP上传到服务器或者Linux虚拟机的/usr/local目录下 3.解压文件tar -z ...
- linux上安装redis4.0.9
redis安装从3.0的版本到现在4.0的版本,现在装一个4.0的版本供大家学习使用. 先yum安装gcc yum -y install gcc 已加载插件:fastestmirror, langpa ...
- tomcat常见错误处理
1 .java.lang.IllegalArgumentException: Document base /XXX/tomcat/webapps/manager does not exist 解决方法 ...
- github 最新项目快报
http://www.open-open.com/github/view/github2016-10-17.html
- 理解WSGI
WSGI是什么? WSGI,全称 Web Server Gateway Interface,或者 Python Web Server Gateway Interface ,是为 Python 语言定义 ...
- linux 备忘记录
杂项记录 Ubuntu 通过/etc/network/interfaces修改IP,重启网络服务貌似也不会生效.可以重启电脑使其生效,或执行: ip addr flush dev ens33 & ...
- 关于一点儿对仓储(Repository)的理解
仓储(Repository) 内容来源于dudu的 关于Repository模式一文 Repository是一个独立的层,介于领域层与数据映射层(数据访问层)之间.它的存在让领域层感觉不到数据访问层的 ...