107国道吧 关注:33贴子:113
  • 0回复贴,共1

1008: Horcrux

只看楼主收藏回复

#include<iostream>
#include<string>
#incldue<cstring>
using namespace std;
const int MAXN = 100010;
unsigned short s[MAXN];
int main()
{
int t,f,top,ans,i,n,x;
while(cin>>n)
{
top = ans = 0;
memset(s,0,sizeof(s));
cin>>f;
t = f;
s[++top] = 1;
for(i = 1; i < n; i++)
{
cin>>x;
if(f!=x)
{
f = x;
if(i%2 && top)
if(top > 1)
s[top-1] += s[top]+1,top--;
else
s[top]++,t = !t;
else s[++top] = 1;
}
else s[top]++;
}
if(top%2 == t) top--;
while(top > 0)
{
ans += s[top];
top -= 2;
}
cout<<ans<<endl;
}
return 0;
}


IP属地:江苏1楼2014-06-14 20:16回复