HDU - 6197 array array array (2017 ACM-ICPC 亚洲区 (沈阳赛区) 网络赛 1004)
2017-09-10 22:48
447 查看
array array array
Problem DescriptionOne 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≤105
0≤k≤n
1≤Ai≤105
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
2017 ACM/ICPC Asia Regional Shenyang Online
题意:给你一串数字,问你能否去掉k个数后,剩下的数列是递增的或递减的。
解题思路:nlogn求最长上升子序列和最长下降子序列即可。
#include<iostream>
#include<deque>
#include<memory.h>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#define INF 1<<29
#define MAXN 100005
using namespace std;
int A[100005];
int B[100005];
int dp[100005];
int main() {
int t;
scanf("%d",&t);
int n,k;
while(t--){
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
scanf("%d",&A[i]);
B[i]=-A[i];//反过来
}
fill(dp,dp+MAXN,INF);
for(int i = 0;i < n;i++){
*upper_bound(dp,dp+n,A[i]) = A[i];
}
int iii=(lower_bound(dp,dp+n,INF)-dp);//最长上升子序列长度
int inum=n-iii;//可以去掉多少个数
fill(dp,dp+MAXN,INF);
for(int i = 0;i < n;i++){
*upper_bound(dp,dp+n,B[i]) = B[i];
}
int ddd=(lower_bound(dp,dp+n,INF)-dp);//最长下降子序列长度
int dnum=n-ddd;//可以去掉多少个数
if(inum<=k||dnum<=k||n==k)//空串也算递增或下降
printf("A is a magic array.\n");
else
printf("A is not a magic array.\n");
}
return 0;
}
相关文章推荐
- HDU - 6201 transaction transaction transaction (2017 ACM-ICPC 亚洲区 (沈阳赛区) 网络赛 1008)
- HDU - 6195 cable cable cable (2017 ACM-ICPC 亚洲区 (沈阳赛区) 网络赛 1002)
- HDU - 6198 number number number (2017 ACM-ICPC 亚洲区 (沈阳赛区) 网络赛 1005)
- HDU - 6205 card card card (2017 ACM-ICPC 亚洲区 (沈阳赛区) 网络赛 1012)
- HDU6201 | 2017 ACM-ICPC 亚洲区(沈阳赛区)网络赛-H transaction transaction transaction
- HDU - 6213 Chinese Zodiac (2017 ACM-ICPC 亚洲区 (青岛赛区) 网络赛 1008)
- HDU - 6214 Smallest Minimum Cut (2017 ACM-ICPC 亚洲区 (青岛赛区) 网络赛 1009)
- HDU6201 | 2017 ACM-ICPC 亚洲区(沈阳赛区)网络赛-H transaction transaction transaction
- HDU - 6206 Apple (2017 ACM-ICPC 亚洲区 (青岛赛区) 网络赛 1001)
- HDU - 6216 A Cubic number and A Cubic Number (2017 ACM-ICPC 亚洲区 (青岛赛区) 网络赛 1011)
- HDU6195 | 2017 ACM-ICPC 亚洲区(沈阳赛区)网络赛-B cable cable cable
- HDU - 6208 The Dominator of Strings (2017 ACM-ICPC 亚洲区 (青岛赛区) 网络赛 1003)
- hdu 5898 odd-even number 2016ACM/ICPC沈阳赛区网络赛1007
- hdu 5893 List wants to travel 2016ACM/ICPC沈阳赛区网络赛1002
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 Query on a string(字符串+树状数组)
- hihoCoder - 1586 Minimum (2017 ACM-ICPC 亚洲区 (北京赛区) 网络赛 I)
- 计蒜客-2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛H题Skiing(拓扑序求DAG最长路)
- 计蒜客 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B coin(求乘法逆元)
- 2017 ACM-ICPC 亚洲区(沈阳赛区)网络赛 - 02 04 05 08 12
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛