zoukankan      html  css  js  c++  java
  • 【习题 8-4 UVA

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    考虑删掉第i位。 则第i+1位就会取代第i位。 则肯定第i+1位比第i位大的话,才比较好。 则从小到大贪心删,找到第一个a[i+1]>a[i]的i. 然后每次删掉这样的i就可以了。

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
      	8.whatch out the detail input require
    */
    /*
        一定在这里写完思路再敲代码!!!
    */
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 1e5;
    
    int n,d,l[N+10],r[N+10];
    char s[N+10];
    
    void sc(int x){
        int L = l[x],R = r[x];
        r[L] = R;
        l[R] = L;
    }
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
        while (cin >> n >> d && n && d){
            cin >> (s+1);
            for (int i = 0;i <= n;i++)
                l[i] = i-1,r[i] = i+1;
            int now = r[0];
            while (1){
                if (d==0)break;
                int nex = r[now];
                while (nex <= n && s[nex]<=s[now]){
                    now = r[now];
                    nex  = r[nex];
                }
                sc(now);
                now = l[now];
                if (now==0) now = r[now];
                d--;
            }
            for (int i = r[0];i!=n+1;i=r[i])
                cout << s[i];
            cout << endl;
        }
    	return 0;
    }
    
  • 相关阅读:
    elasticsearch7.1 安装启动报错
    jvm调优
    基于redis实现IP访问频次控制
    docker 搭建redis集群
    Tomcat安全配置与性能优化
    mybaties 的 applicationContext.xml
    SSH阶段常见错误及说明
    hibernate 7种映射关系
    (四)SpringBoot如何定义消息转换器
    java之package与import
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8228023.html
Copyright © 2011-2022 走看看