HDU
来源:互联网 发布:柯尔特蟒蛇357淘宝模型 编辑:程序博客网 时间:2024/06/08 09:10
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197
题目大意:n个数,问从n个数中删除k个,能否形成非严格单调的数列
解题思路:找出最长非严格单调序列的长度l,比较l+k与n的大小关系,找最长单调子序列可以参考博客:http://blog.csdn.net/nightmare_ak/article/details/77925962
AC代码:
#include<cstdio>#include<algorithm>using namespace std;const int MAXN = 100000 + 5;int Ans[MAXN], gt[MAXN], tot;void toSolve(int n){ tot = 0; Ans[tot++] = gt[0]; for (int i = 1;i < n;++i) { if (gt[i] >= Ans[tot - 1]) Ans[tot++] = gt[i]; else { int pos = upper_bound(Ans, Ans + tot, gt[i]) - Ans; Ans[pos] = gt[i]; } }}int main(){ int t;scanf("%d", &t); while (t--) { int n, k; scanf("%d%d", &n, &k); for (int i = 0;i < n;++i) scanf("%d", gt + i); toSolve(n); if (tot + k >= n) { puts("A is a magic array."); continue; } reverse(gt, gt + n);//若为单减,反转一下转化成求最长非严格单增子序列 toSolve(n); if (tot + k >= n) puts("A is a magic array."); else puts("A is not a magic array."); } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 数据结构-单线性链式-头插法
- mysql MyISAM和InnoDB
- SpringBoot多表查询的实现
- Tensorflow学习笔记:About Session, Graph, Operation and Tensor
- java timer缺陷
- HDU
- 敏捷开发之类的摘抄
- centos7安装mysql
- xlistview布局
- webpack入门
- logistic回归总结
- 为什么要开展压力测试 和 什么时候开展压力测试
- 【软考】--数据库基础
- 【强连通分量】CEOI2012network