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

  • 相关阅读:
    推荐系统(二)
    应用高斯分布来解决异常检测问题(三)
    应用高斯分布来解决异常检测问题(二)
    应用高斯分布来解决异常检测问题(一)
    高斯(正态)分布、GDA、Mixtures of Gaussian
    主成分分析
    logistic回归
    推荐系统(一)
    基于朴素贝叶斯模型的文本分类
    K均值聚类算法
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7616412.html
Copyright © 2011-2022 走看看