zoukankan      html  css  js  c++  java
  • Codeforces 846 A Curriculum Vitae 思维 暴力

      题目链接: http://codeforces.com/contest/846/problem/A

      题目描述: 给你一个串, 你可以做删除操作, 要求结果串0不能在1的右边, 问最多可以剩几个数字

      解题思路: 我们可以看最后的结果是什么, 结果一定是全0或者全1, 或左0右1, 这样我们暴力枚举分割点就可以了

      代码: 

    #include <iostream>
    #include <cstdio>
    #include <map>
    #include <iterator>
    #include <string>
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <cstring>
    using namespace std;
    
    typedef long long ll;
    const int maxn = 1e2+10;
    int a[maxn];
    
    int main() {
        int n;
        cin >> n;
        int ans1, ans0;
        ans1 = ans0 = 0;
        for( int i = 1; i <= n; i++ ) {
            cin >> a[i];
            if( a[i] == 0 ) ans0++;
            else ans1++;
        }
        int ans = 0;
        for( int i = 1; i <= n; i++ ) {
            int cnt0,cnt1;
            cnt0 = cnt1 = 0;
            for( int j = 1; j <= i; j++ ) {
                if( a[j] == 0 ) cnt0++;
            }
            for( int j = i+1; j <= n; j++ ) {
                if( a[j] == 1 ) cnt1++;
            }
            ans = max(cnt1+cnt0, ans);
            
            cnt0 = cnt1 = 0;
            for( int j = 1; j < i; j++ ) {
                if( a[j] == 0 ) cnt0++;
            }
            for( int j = i; j <= n; j++ ) {
                if( a[j] == 1 ) cnt1++;
            }
            ans = max(cnt1+cnt0, ans);
            
        }
    
        cout << max(ans, max(ans1, ans0)) << endl;
        return 0;
    }
    View Code

      思考: 一开始忘了初始化了, WA了一发, MDZZ!!!

    http://codeforces.com/contest/846/problem/A

  • 相关阅读:
    elasticsearch如何设计索引
    LinkedList 的实现原理
    聊聊elasticsearch7.8的模板和动态映射
    elasticsearch7.8权限控制和规划
    cloudera manager server迁移
    2020年终总结
    工作两年半的一次复盘
    聊聊数据结构和算法
    AutoMapper源码解析
    [源码解析] 并行分布式框架 Celery 之 worker 启动 (2)
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7616412.html
Copyright © 2011-2022 走看看