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

  • 相关阅读:
    ES6学习笔记(七)-对象扩展
    ES6学习笔记(四)-数值扩展
    ES6学习笔记(三)-正则扩展
    ES6学习笔记(二)-字符串的扩展
    ES6学习笔记(一)-变量的解构赋值
    webpack打包踩坑之TypeError: Cannot read property 'bindings' of null
    CSS之Flex 布局
    iscsi
    DHCP
    DNS
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7616412.html
Copyright © 2011-2022 走看看