标签:magic lease php nbsp rom path mission others col
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 114 Accepted Submission(s): 65
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\n", lis, lds); 57 if(n-k <= lis || n-k <= lds) 58 printf("A is a magic array.\n"); 59 else 60 printf("A is not a magic array.\n"); 61 } 62 63 return 0; 64 }
标签:magic lease php nbsp rom path mission others col
原文地址:http://www.cnblogs.com/Penn000/p/7502249.html