1 条题解

  • 0
    @ 2022-4-16 16:20:53

    好题怎么能没有题解呢?

    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    typedef long long LL;
    const int MAXN = 1e6 + 10;
    const int INF = 0x3f;
    int a[MAXN];
    int qian[MAXN];
    int main()
    {
    	int n;
    	cin >> n;
    	int Max = n;
    	for(int i = 1;i <= n; i++){
    		cin >> a[i];
    		if(a[i] == 2){
    			qian[i] = qian[i - 1] + 1;
    		}
    		else{
    			qian[i] = qian[i - 1];
    		}
    	}
    	for(int i = 1;i <= n; i++){
    		Max = min(Max, 2 * qian[i] + n - i - qian[n]);
    	}
    	if(Max == n){
    		cout << 0;
    	}
    	else cout << Max;
        return 0;
    }
    
    
    • 1

    信息

    ID
    1820
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    递交数
    12
    已通过
    5
    上传者