zoukankan      html  css  js  c++  java
  • Codeforces 1321C Remove Adjacent

    题目链接

    2s+n=100,可以直接暴力贪心,从末尾z开始删到a即可

    #include<bits/stdc++.h>
    using namespace std;
    #define ms(x,y) memset(x, y, sizeof(x))
    #define lowbit(x) ((x)&(-x))
    typedef long long LL;
    typedef pair<int,int> pii;
    
    
    void run_case() {
        int n;
        string str;
        cin >> n >> str;
        int ans = 0;
        for(int k = 25; k >= 0; --k) {
            for(int t = 0; t < 100; ++t) {
                for(int i = 0; i < str.size(); ++i) {
                    if((str[i] - 'a' == k) && ((str[i-1] - 'a' == k-1) || (str[i+1] - 'a' == k-1))) {
                        ans++;
                        str.erase(i, 1);
                        i--;
                    }
                }
            }
        }
        cout << ans;
    }
    
    int main() {
        ios::sync_with_stdio(false), cin.tie(0);
        cout.flags(ios::fixed);cout.precision(2);
        //int t; cin >> t;
        //while(t--)
        run_case();
        cout.flush();
        return 0;
    }
    
  • 相关阅读:
    省选测试13
    省选测试12
    省选测试11
    省选测试9
    省选测试10
    省选测试8
    省选测试7
    省选测试6
    倍增 LCA && ST表
    博客园markdown
  • 原文地址:https://www.cnblogs.com/GRedComeT/p/12442873.html
Copyright © 2011-2022 走看看