• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
LyonLys
愿意在角落唱沙哑的歌 再大声也都是给你 请用心听 不要说话 Contact me via E-mail: lyon.lys@gmail.com
博客园    首页    新随笔    联系   管理    订阅  订阅

BUAA 169 电话费

http://oj55.bianchengla.com/problem/169/

  还有这个,不怎么好做,最后用栈做出来了。

感觉比较有用的一个数据是:

10 3

1010101010

代码如下:

 1 #include <cstdio>
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 const int N = 11111;
 7 int n, k;
 8 char s[N], stk[N], mx[N];
 9 
10 int main() {
11     while (~scanf("%d%d%s", &n, &k, s)) {
12         int top = -1;
13         if (k == n - 1) {
14             char mn = '9';
15             for (int i = 0; i < n; i++) mn = min(s[i], mn);
16             putchar(mn); puts("");
17             continue;
18         }
19         for (int i = 0; i < n; i++) {
20             if (s[i] != '0') while (~top && k >= top + 1 && mx[top] > s[i]) top--, k--;
21             while (k && ~top && stk[top] > s[i]) {
22                 if (s[i] == '0' && top == 0) break;
23                 top--; k--;
24             }
25             stk[++top] = s[i];
26             if (top > 0) mx[top] = max(s[i], mx[top - 1]);
27             else mx[top] = s[i];
28         }
29         while (k--) top--;
30         //printf("top %d\n", top);
31         for (int i = 0; i <= top; i++) putchar(stk[i]); puts("");
32     }
33     return 0;
34 }
View Code

 

——written by Lyon

posted @ 2013-12-18 18:15  LyonLys  阅读(171)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3