您的位置:首页 > 其它

找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

2015-06-29 16:48 519 查看
题目传送门

 /*
找规律/贪心:ans = n - 01匹配的总数,水
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;

const int MAXN = 2e5 + 10;
const int INF = 0x3f3f3f3f;
char s[MAXN];

int main(void)        //Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
{
// freopen ("A.in", "r", stdin);

int n;
while (scanf ("%d", &n) == 1)
{
scanf ("%s", s);
int cnt_0 = 0, cnt_1 = 0;
for (int i=0; i<n; ++i)
{
if (s[i] == '0')    cnt_0++;
else    cnt_1++;
}

printf ("%d\n", n - min (cnt_0, cnt_1) * 2);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: