Uva - 11491 - Erasing and Winning
2015-06-23 17:06
344 查看
刚开始用选择思维一个一个选,现在前n-d+1个里面找到最大值,是最高位,逐渐找下去,直接TLE了,果然这样直接做负责度太高。
然后改用边读入边处理,新读入一个,往前找,是否有合适的位置放,有就删除原来的占位。
AC代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cctype> #include <cstring> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <algorithm> #include <stack> #include <queue> #include <bitset> #include <cassert> #include <cmath> #include <functional> using namespace std; const int maxn = 100005; int s[maxn]; int main() { int n, d; while (scanf("%d%d%*c", &n, &d) && n) { int t = 0; int a; d = n - d; for (int i = 0; i < n; i++) { a = getchar() - '0'; while (t && t + n - i > d && a > s[t - 1]) { t--; } if (t < d) { s[t++] = a; } } for (int i = 0; i < t; i++) { printf("%d", s[i]); } printf("\n"); } return 0; }
相关文章推荐
- 《第一行代码——Android》
- Uva - 11491 - Erasing and Winning
- 模仿QQ侧滑样式,借鉴了张鸿洋的最简单侧滑
- android基础学习之RSA加密解密
- AES 文档加密器
- Windows系统环境变量path优先级测试报告
- java通过封装编写Book类。要求:类具有属性书名、书号、主编、出版社、出版时间、页数、价格,其中页数不能少于200页,否则输出错误信息,并强制赋默认值200;为各属性设置赋值和取值方法;具有方法d
- 将2个家庭小路由连接在一起
- linux登录windows服务器
- pthread_once()函数详解
- Linux_4.6_信号量互斥编程
- Love 0.9.2变化(相对于0.9.1)
- 【Qt编程】基于Qt的词典开发系列<九>--JSON数据解析
- IAR_FOR_STM8开发之DEMO的建立
- goagent安装和使用
- Resin优化方案
- 从机器学习谈起
- win7系统下将Editplus添加到鼠标右键菜单的方法
- Genymotion Unable to load VirtualBox engine
- Codeforces 552C Vanya and Scales