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?
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 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~