2017微软秋季校园招聘在线编程笔试A
看N的范围就知道是用什么复杂度的算法了
用个stack存就好了
#define LOG(x) cout << #x << " = " << (x) << endl
#define PRINTLN(x) cout << (x) << endl
#define MEM(x, y) memset((x), (y), sizeof((x)))
#include <bits/stdc++.h>
using namespace std;
const double PI = 2*acos(0);
typedef long long ll;
typedef complex<double> Complex;
int nextInt()
{
int x;
scanf("%d", &x);
return x;
}
ll nextLL()
{
ll x;
scanf("%lld", &x);
return x;
}
//TEMPLATE
//MAIN
int main()
{
//freopen("in.txt", "r", stdin);
int n;
while (scanf("%d", &n) != EOF) {
stack<ll> s;
int ans = 0;
for (int i = 0; i < n; i++) {
ll t = nextLL();
if (!s.empty() && (s.top() + t) % 2) {
s.pop();
ans += 2;
} else s.push(t);
}
PRINTLN(n - ans);
}
}