Problem 1004-2017 ACM/ICPC Asia Regional Shenyang Online
- 题目来源:array array array
- Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0 - 题目描述和输出:
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≤10^5
0≤k≤n
1≤Ai≤10^5 - 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. - 题目分析:
有T个测试样例,对于每个测试样例,给定两个整数,分别是数组元素个数n和需要删除的元素个数k,如果这个数组在删除了k个元素之后,是递增或者递减的,就称这个数组是magic array,否则不是。 - 做法:这道题是个经典的DP,换句话说就是模板题。
- 完整代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 100005
#define INF 100000000
int dp[MAX];
int a[MAX];
int k, T, n, flag;
int main()
{
int temp;
cin >> T;
while (T-- > 0)
{
cin >> n >> k;
memset(a, 0, sizeof(int)*MAX);
for (int i = 0; i < n; i++)
cin >> a[i];
fill(dp, dp + n, INF);
for (int i = 0; i < n; i++)
{
*upper_bound(dp, dp + n, a[i]) = a[i];
}
temp = 0;
while (dp[temp]<INF)
{
temp++;
}
if (temp >= n - k)
printf("A is a magic array.\n");
else
printf("A is not a magic array.\n");
}
return 0;
}
Problem 1004-2017 ACM/ICPC Asia Regional Shenyang Online的更多相关文章
- 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路
transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ...
- 2017 ACM/ICPC Asia Regional Shenyang Online transaction transaction transaction
Problem Description Kelukin is a businessman. Every day, he travels around cities to do some busines ...
- 2017 ACM/ICPC Asia Regional Shenyang Online cable cable cable
Problem Description Connecting the display screen and signal sources which produce different color s ...
- 2017 ACM/ICPC Asia Regional Shenyang Online
cable cable cable Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 2017 ACM/ICPC Asia Regional Shenyang Online 记录
这场比赛全程心态爆炸…… 开场脑子秀逗签到题WA了一发.之后0贡献. 前期状态全无 H题想复杂了,写了好久样例过不去. 然后这题还是队友过的…… 后期心态炸裂,A题后缀数组理解不深,无法特判k = 1 ...
- 2017 ACM/ICPC Asia Regional Shenyang Online:number number number hdu 6198【矩阵快速幂】
Problem Description We define a sequence F: ⋅ F0=0,F1=1;⋅ Fn=Fn−1+Fn−2 (n≥2). Give you an integer k, ...
- 2017 ACM/ICPC Asia Regional Shenyang Online(部分题解)
HDU 6197 array array array 题意 输入n和k,表示输入n个整数和可以擦除的次数k,如果至多擦除k次能是的数组中的序列是不上升或者是不下降序列,就是魔力数组,否则不是. 解题思 ...
- HDU 6205(尺取法)2017 ACM/ICPC Asia Regional Shenyang Online
题目链接 emmmm...思路是群里群巨聊天讲这题是用尺取法.....emmm然后就没难度了,不过时间上3000多,有点.....盗了个低配本的读入挂发现就降到2800左右, 翻了下,发现神犇Clar ...
- HDU 6198(2017 ACM/ICPC Asia Regional Shenyang Online)
思路:找规律发现这个数是斐波那契第2*k+3项-1,数据较大矩阵快速幂搞定. 快速幂入门第一题QAQ #include <stdio.h> #include <stdlib.h& ...
- 2017 ACM/ICPC Asia Regional Shenyang Online array array array
2017-09-15 21:05:41 writer:pprp 给出一个序列问能否去掉k的数之后使得整个序列不是递增也不是递减的 先求出LIS,然后倒序求出最长递减子序列长度,然后判断去k的数后长度是 ...
随机推荐
- 转:99%的人都理解错了HTTP中GET与POST的区别
原贴来自:http://www.techweb.com.cn/network/system/2016-10-11/2407736.shtml GET和POST是HTTP请求的两种基本方法,要说它们的区 ...
- 工作采坑札记:3. Spark中es-hadoop插件异常解决
1. Es-Hadoop异常: org.elasticsearch.hadoop.EsHadoopException: Could not write all entries [615/300864] ...
- Unity Shader 学习笔记(一)
_MainTex_ST (1)简单来说,TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)主要作用是拿顶点的uv去和材质球的t ...
- 接口调试,HttpWebRequest和HttpWebResponse使用,接口回调处理
public void queryIdCardSelects { string url=“jiekoudizhi.html”; string param="jiekoucanshu" ...
- C#用委托实现异步,异步与多线程的异同
异步与多线程的区别(转) 一.异步和多线程有什么区别?其实,异步是目的,而多线程是实现这个目的的方法.异步是说,A发起一个操作后(一般都是比较耗时的操作,如果不耗时的操作就没有必要异步了),可以继续自 ...
- 我的Android开发之路——百度地图开源工具获取定位信息
定位技术在现在的移动设备上是必不可少的,许多app都会使用定位功能. 通常定位方式有两种:GPS定位:网络定位. Android系统对这两种定位方式都提供了相应的API支持,但是因为google的网络 ...
- SQL SERVER 错误代码 0x534
解决办法就是修改一下登陆名: ALTER LOGIN [G-PC\zqwang] WITH NAME=[新的机器名\zqwang]; 然后查询一下 Service Broker 队列, 里面已经有 ...
- Struts2_总结
还未学习的内容,如果到时候要用到,再去学.1.Lamda 表达式(很复杂,很少用)2.验证框架(默认验证方法 validation.方法开始前验证.开始后验证)3.UI标签(用的不多)4.类型转换中的 ...
- 算法练习-Palindrome Number
判断回文整数 来源 https://leetcode.com/problems/palindrome-number/ 要求 判断一个整数是不是回文数,尽量减少内存暂用. 思路 可能的情况: 负数的应当 ...
- DB2安装教程图解
下载好之后,是exe文件,但是双击后基本上都是解压,但是使用自身的解压的话会有很多文件解压失败的情况,所以推荐使用自己电脑上自带的解压工具直接解压(如360解压,好压等). 解压之后直接运行setup ...