Problem 1004-2017 ACM/ICPC Asia Regional Shenyang Online
2024-09-07 07:33:45
- 题目来源: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;
}
最新文章
- JS区分移动端和PC
- echarts在.Net中使用实例(一) 简单的Demo
- 如何静态添加toolbar到datagrid
- asp.net生成随机密码
- ajaxfileupload回到json带<;pre>;
- jQuery uploadify上传文件404,500错误
- JavaScript运算符
- 介绍NSURLSession网络请求套件
- CSS Devices可以让你在线直接获取使用CSS写的Mobile外形。
- 推荐《Linux 多线程服务器端编程》
- 执行计划之CONCATENATION
- iOS之UISearchBar实时显示结果
- maven GroupId 和ArtifactId的含义
- html5 css练习,弹性三栏布局
- saltstack高效运维
- [Maven]Maven如何得到单独的单元测试报告
- hdu5517 二维树状数组
- JAVA面对对象(四)——抽象类
- Linux系统查看日志信息总结
- java资料共享
热门文章
- 注意mysql connector的版本
- LitJson(读Exce文件写入到json文件):
- 案例53-crm练习修改客户功能实现
- HDU 3829——Cat VS Dog——————【最大独立集】
- dt4.0上传图片总是压缩解决办法,为什么我设置了不压缩图片,程序还是压缩呢?
- SpingCloud微服务架构学习(二)之Actuator监控
- hibernate课程 初探一对多映射2-3 创建hibernateUtil工具类
- 基于百度ai,图灵机器人,Flask 实现的网站语音智能问答
- <;Android 基础(十三)>; shape
- ComponentOne、Spread、ActiveReports 5折起 加入惊喜惠