zoukankan      html  css  js  c++  java
  • 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

    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,A2An.
    1T20
    1n105
    0kn
    1Ai105
     

    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.
     

    Source

     
     1 //2017-09-10
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <iostream>
     5 #include <algorithm>
     6 
     7 using namespace std;
     8 
     9 const int N = 110000;
    10 int arr[N], rarr[N], n, k;
    11 int dp1[N], dp2[N];
    12 
    13 int Search(int* dp,int len,int num){  
    14     int low = 1,high = len;  
    15     while(low <= high){  
    16             int mid = (low + high) >> 1;  
    17             if (num == dp[mid]) return mid;  
    18             if (dp[mid] < num) low = mid + 1;  
    19             else high = mid - 1;  
    20         }  
    21     return low;  
    22 }  
    23 
    24 int main()
    25 {
    26     int T;
    27     scanf("%d", &T);
    28     while(T--){
    29         scanf("%d%d", &n, &k);
    30         for(int i = 1; i <= n; i++)
    31               scanf("%d", &arr[i]);
    32         for(int i = 1; i <= n; i++)
    33               rarr[i] = arr[n-i+1];
    34         int lis = 1;
    35         dp1[0] = -1;
    36         dp1[1] = arr[1];
    37         for(int i = 1; i <= n; i++){
    38             if(arr[i] > dp1[lis])
    39                   dp1[++lis] = arr[i];
    40             else{
    41                 int pos = Search(dp1, lis, arr[i]);
    42                 dp1[pos] = arr[i];
    43             }
    44         }
    45         int lds = 1;
    46         dp2[0] = -1;
    47         dp2[1] = rarr[1];
    48         for(int i = 1; i <= n; i++){
    49             if(rarr[i] > dp2[lds])
    50                   dp2[++lds] = rarr[i];
    51             else{
    52                 int pos = Search(dp2, lds, rarr[i]);
    53                 dp2[pos] = rarr[i];
    54             }
    55         }
    56         //printf("%d %d
    ", lis, lds);
    57         if(n-k <= lis || n-k <= lds)
    58               printf("A is a magic array.
    ");
    59         else
    60               printf("A is not a magic array.
    ");
    61     }
    62 
    63     return 0;
    64 }
  • 相关阅读:
    Jetson TX1使用usb camera采集图像 (2)
    Jetson TX1安装pyTorch
    Jetson TX1 install Opencv3
    Jetson TX1使用usb camera采集图像 (1)
    win10双系统安装卸载ubuntu
    弱监督下的目标检测算法
    javascript高级程序设计读书笔记
    好用的linux命令
    正则表达式学习
    yii执行原理
  • 原文地址:https://www.cnblogs.com/Penn000/p/7502249.html
Copyright © 2011-2022 走看看