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的数后长度是 ...
随机推荐
- 性能测试工具Jmeter01-简介
Jmeter介绍: Apache JMeter是Apache组织的开放源代码项目,是一个纯Java桌面应用,用于压力测试和性能测试.最初被设计用于Web应用测试后来扩展到其它测试领域 Jmeter有啥 ...
- mysql 不能插入中文记录
问题: # ERR: Incorrect string value: '\xE5\xAD\x9F\xE5\xBB\xBA...' for column 'chinese_name' at row 1 ...
- 利用Intent.ACTION_SEND进行分享
安卓系统本身可以很简便的实现分享功能,因为我们只需向startActivity传递一个ACTION_SEND的Intent,系统就为我们弹出一个应用程序列表.其实在系统的文件管理器中,这应该是我们常用 ...
- LeetCode 303.区域检索-数组不可变(accumulate()和for循环差异分析)
给定一个整数数组 nums,求出数组从索引 i 到 j (i ≤ j) 范围内元素的总和,包含 i, j 两点. 示例: 给定 nums = [-2, 0, 3, -5, 2, -1],求和函数 ...
- MATLAB字符串处理
字符串处理 MATLAB中字符串用单引号 如果字符串中存在单引号,要使用两个单引号. length()元素个数 (1)字符串的执行 格式:eval(s) s表示字符串 abs()和double() ...
- GET和POST区别和用法
很多人都分不清GET与POST的区别,以及什么时候用GET?什么时候用POST? GET和POST两种方法都是将数据送到服务器,但你该用哪一种呢? HTTP标准包含这两种方法是为了达到不同的目的.PO ...
- 接口调试,HttpWebRequest和HttpWebResponse使用,接口回调处理
public void queryIdCardSelects { string url=“jiekoudizhi.html”; string param="jiekoucanshu" ...
- Spring课程 Spring入门篇 3-3 Spring bean装配(上)之aware接口
课程链接: 本节主要介绍了以下内容: 1 aware介绍 2 代码演练 3 课程总结 1 aware介绍 1.1 为什么要使用aware? 在java类中,可以方便的获取xml配置文件中的bean的各 ...
- Azure 进阶攻略 | 上云后的系统,「门禁」制度又该如何实现?
各位办公室白领们,不妨回想一下自己每天去公司上班时的一些细节. 为避免「闲杂人等」进入工作场所,我们需要证明自己是这家公司的员工才能进入,对吧!所有员工,无论所属部门或职位,都必须先证明自己身份,例如 ...
- 第五章 存储过程&触发器
1.前言 2.存储过程和触发器->存储过程 ·理解:是一组SQL命令集合,经过预编译存放在系统中:就像java程序里的方法,可以重复的被调用: 在日常的数据库操作中,会有大量的T-SQL批处理. ...