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

  • 相关阅读:
    CentOS 6.4 系统下的MySQL的主从库配置
    扫盲: JAVA基本常识
    ant学习
    Linux一些命令
    redis学习
    扫盲:注册表和绿色软件常识
    Java.前端.Layer.open.btn验证无效
    Java.数据结构.集合体系详解
    PageHelper踩坑
    Scrum.站立会议介绍
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7616412.html
Copyright © 2011-2022 走看看