zoukankan      html  css  js  c++  java
  • Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones 水题

    A. Case of the Zeros and Ones

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

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

    Description

    Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.

    Once he thought about a string of length n consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length n - 2 as a result.

    Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.

    Input

    First line of the input contains a single integer n (1 ≤ n ≤ 2·105), the length of the string that Andreid has.

    The second line contains the string of length n consisting only from zeros and ones.

    Output

    Output the minimum length of the string that may remain after applying the described operations several times.

    Sample Input

    4
    1100

    Sample Output

    0

    HINT

    题意

    10会消掉,然后问你最后剩下多少个数字

    题解:

    最后要么只剩下0,要么只剩下1,所以就是0的个数或者1的个数咯

    代码

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef unsigned long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 2000001
    #define mod 1000000007
    #define eps 1e-9
    int Num;
    char CH[20];
    const int inf=0x3f3f3f3f;
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    
    //**************************************************************************************
    
    int main()
    {
        int n=read();
        string s;
        cin>>s;
        int ans=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='1')
                ans++;
            else
                ans--;
        }
        cout<<abs(ans)<<endl;
    }
  • 相关阅读:
    [原创]Office Word 2010如何使用printer drivers输出PostScript文件
    MATLAB启动时报错: pathdef.m not found 问题解决方法
    Ubuntu 下 Matlab R2010a 错误:`GLIBCXX_3.4.11' not found 的解决办法
    [转] 一阶导和二阶导的含义
    win7 搭建ftp 设置用户权限 远程访问设置
    Ubuntu 中软件的安装、卸载以及查看的方法总结
    64位ubuntu12.04 LTS安装oracle10g笔记
    如何在Ubuntu 12.04 LTS中使用低版本gcc/g++
    HTTP与HttpServlet
    EXP00091错误
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4605010.html
Copyright © 2011-2022 走看看