• 题目来源: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的更多相关文章

  1. 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  2. 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 ...

  3. 2017 ACM/ICPC Asia Regional Shenyang Online cable cable cable

    Problem Description Connecting the display screen and signal sources which produce different color s ...

  4. 2017 ACM/ICPC Asia Regional Shenyang Online

    cable cable cable Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. 2017 ACM/ICPC Asia Regional Shenyang Online 记录

    这场比赛全程心态爆炸…… 开场脑子秀逗签到题WA了一发.之后0贡献. 前期状态全无 H题想复杂了,写了好久样例过不去. 然后这题还是队友过的…… 后期心态炸裂,A题后缀数组理解不深,无法特判k = 1 ...

  6. 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, ...

  7. 2017 ACM/ICPC Asia Regional Shenyang Online(部分题解)

    HDU 6197 array array array 题意 输入n和k,表示输入n个整数和可以擦除的次数k,如果至多擦除k次能是的数组中的序列是不上升或者是不下降序列,就是魔力数组,否则不是. 解题思 ...

  8. HDU 6205(尺取法)2017 ACM/ICPC Asia Regional Shenyang Online

    题目链接 emmmm...思路是群里群巨聊天讲这题是用尺取法.....emmm然后就没难度了,不过时间上3000多,有点.....盗了个低配本的读入挂发现就降到2800左右, 翻了下,发现神犇Clar ...

  9. HDU 6198(2017 ACM/ICPC Asia Regional Shenyang Online)

    思路:找规律发现这个数是斐波那契第2*k+3项-1,数据较大矩阵快速幂搞定.   快速幂入门第一题QAQ #include <stdio.h> #include <stdlib.h& ...

  10. 2017 ACM/ICPC Asia Regional Shenyang Online array array array

    2017-09-15 21:05:41 writer:pprp 给出一个序列问能否去掉k的数之后使得整个序列不是递增也不是递减的 先求出LIS,然后倒序求出最长递减子序列长度,然后判断去k的数后长度是 ...

随机推荐

  1. macOS 使用软件(外加装逼特效)

    macOS 使用软件(外加装逼特效) Backgroud 和 火萤: 动态桌面壁纸 iTools Pro: macOS 版本的爱思助手 MEGAsync: 网盘工具 Microsoft Remote ...

  2. Linux kernel rbtree

    Linux kernel rbtree 因编写内核模块时需要用到rbtree来记录异步request,研究分析了一下kernel rbtree的使用方法,记录于此.本文主要参考了内核文档rbtree. ...

  3. 在DataColumn.Expression把DateTime转换成String的问题

    我在使用MySql5.1的数据库中,使用winForm的DataGridView要把数据库中全称DateTime格式,转换成Date格式,就是把日期时间转换成日期,不要时间.如‘2013-07-08 ...

  4. iDempiere 使用指南 采购开票付款流程

    Created by 蓝色布鲁斯,QQ32876341,blog http://www.cnblogs.com/zzyan/ iDempiere官方中文wiki主页 http://wiki.idemp ...

  5. Design Pattern ->Composite

    Layering & Contract Philosophy With additional indirection class CComponent { ; ; ; public: virt ...

  6. 解决dubbo-admin管控台不能显示服务的问题

    1.首先在网上下载了dubbo-admin.war,解压后修改dubbo.properties文件 dubbo.registry.address=zookeeper://127.0.0.1:2181 ...

  7. Selenium 元素查找

    1.尽量使用ID或者name去定位元素,如果这个元素没有ID或者Name,那么就是用它最近的父节点的ID或者Name去定位. 2.写自动化脚本不是一个人的事情,是一个团队的事情,合作能更好,更轻松得完 ...

  8. SharePoint 2010 VS.net 2010 断点调试

    当IE打开之后 1在代码的项目:右键:重新生成 2用WSPBuilder的Copy to GAC 3IE要调试的页面:刷新 4用WSPBuilder的Attach to IIS Worker Proc ...

  9. php的yii框架开发总结6

    MVC中的Controller部分,所有的controller类都是继承自Controller基类,基类里面包含actionAdmin-管理员,actionIndex-一般默认显示,actionVie ...

  10. 前端怎样学习react

    这是一个很长的话题.....慢慢写