2017 ACM/ICPC Asia Regional Shenyang Online array array array

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?

题意:去掉一些数字。可以保证是不严格递增或者递减

解法:

求一波最长就行了

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #include<bitset>
 6 #include<vector>
 7 #include<cmath>
 8 #include<bitset>
 9 #include<map>
10 using namespace std;
11 const int N=123456;
12 int b[N];
13 int LIS1(int a[], int n) {
14   int len = 1; b[0] = a[0];
15   for (int i = 1; i < n; i++) {
16     b[a[i] >= b[len - 1] ? len++ : upper_bound(b, b + len, a[i]) - b] = a[i]; 
17   }
18   return len;
19 }
20 int LIS2(int a[], int n) {
21   int len = 1; b[0] = a[0];
22   for (int i = 1; i < n; i++) {
23     b[a[i] <= b[len - 1] ? len++ : lower_bound(b, b + len, a[i]) - b] = a[i]; 
24   }
25   return len;
26 }
27 int a[N];
28 int c[N];
29 int main()
30 {
31     int t;
32     scanf("%d",&t);
33     while(t--){
34        int n,k;
35        scanf("%d%d",&n,&k);
36        for(int i=0;i<n;i++){
37         scanf("%d",&b[i]);
38         }
39         int x=LIS1(b,n);
40         int y=LIS2(b,n);
41         if(x+k>=n||y+k>=n){
42             cout<<"A is a magic array."<<endl;
43         }else{
44             cout<<"A is not a magic array."<<endl;
45         }
46     }
47     return 0;
48 }

 

posted @ 2017-09-19 10:09  樱花落舞  阅读(202)  评论(0编辑  收藏  举报