Description

A Horcrux is an object in which a Dark wizard or witch has hidden a fragment of his or her soul for the purpose of attaining immortality. Constructing a Horcrux is considered Dark magic of the foulest, most evil kind, as it violates laws of nature and morality, and requires a horrific act (a.k.a. murder) to accomplish.

There are two kinds of horcruxes, the white one, denoted as , and the black one, denoted as . Topper has got N horcruxes, and he wants to destroy them to win the Dark wizard. Toper places all the horcruxes in a line from left to right, one by one, and then says a magic spell to destroy them. In order to make the magic spell works, Toper needs to know the number of the white horcruxes.

Since the horcruxes also has magic, when placing the horcruxes, they will change color from white to black or from black to white under the following rules:

  1. When Topper places the i-th horcrux and i is an even number: If the i-th horcrux and the rightmost horcrux have different colors, all consecutive horcruxes of the same color on the right change its color.

  2. In other situations, no magic works.

For example, suppose the horcruxes on the line are:

△△▲▲△△△

After placing 7 horcruxes.

If the 8-th horcrux is white, since its color and the color of the rightmost horcrux are the same. Therefore, the horcruxes on the line become as follows:

△△▲▲△△△△

If the 8-th horcrux is black, since its color and the color of the rightmost horcrux are different, the 3 consecutive white stones on the right change their color. Therefore, the stones on the line become as follows:

△△▲▲▲▲▲▲

You see, it’s not an easy job to beat the Dark wizard. So write a program to help Topper.

Input

There are some test cases. In each test case, the first line contains a positive integer n (1≤n≤100,000), which is the number of horcruxes. The following n lines denote the sequence in which Topper places the horcruxes. 0 stands for white horcrux, and 1 stands for black horcrux.

Output

For each test case, output one line containing only the number of white horcruxes on the line after Topper places n horcruxes.

Sample Input

8
1
0
1
1
0
0
0
0
8
1
0
1
1
0
0
0
1

Sample Output

6
2

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
const int maxn=100005;
int n,x;
struct Node
{
int col,num;
}a[maxn];
int main()
{
while(scanf("%d",&n)!=EOF)
{
int cnt=1;
scanf("%d",&x);
a[cnt].col=x;a[cnt].num=1;
for(int i=2;i<=n;i++)
{
scanf("%d",&x);
if(a[cnt].col==x)
a[cnt].num++;
else
{
if(i%2==0)
{
a[cnt].col=x;
a[cnt].num++;
if(cnt>1)
{
a[cnt-1].num+=a[cnt].num;
cnt--;
}
}
else
{
a[++cnt].col=x;
a[cnt].num=1;
}
}
}
int ans=0;
for(int i=1;i<=cnt;i++)
{
if(a[i].col==0)
ans+=a[i].num;
}
printf("%d\n",ans);
}
return 0;
} /**********************************************************************
Problem: 1008
User: therang
Language: C++
Result: AC
Time:24 ms
Memory:2804 kb
**********************************************************************/

  


CSU1008: Horcrux的更多相关文章

  1. CSUOJ 1008 Horcrux

    Description A Horcrux is an object in which a Dark wizard or witch has hidden a fragment of his or h ...

  2. ural1439 Battle with You-Know-Who

    Battle with You-Know-Who Time limit: 2.0 secondMemory limit: 64 MB Rooms of the Ministry of Magic ar ...

  3. Manthan, Codefest 17

    A. Tom Riddle's Diary time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. Marvolo Gaunt's Ring(巧妙利用前后缀进行模拟)

    Description Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as h ...

  5. codeforce 855B

    B. Marvolo Gaunt's Ring time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. Codeforces 855B:Marvolo Gaunt's Ring(枚举,前后缀)

    B. Marvolo Gaunt's Ring Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaun ...

随机推荐

  1. 【191】◀▶ Powershell 命令集 Cmdlets

     Powershell 命令集 cmdlets cmdlets是Powershell的内部命令,cmdlet的类型名为System.Management.Automation.CmdletInfo,包 ...

  2. P2093 [国家集训队]JZPFAR(KDTree)

    传送门 类似于p4357 不过因为距离相等的时候要优先选择序号小的,所以要重载一下运算符 //minamoto #include<bits/stdc++.h> #define R regi ...

  3. [POI2010]Antisymmetry

    Description 对于一个01字符串,如果将这个字符串0和1取反后,再将整个串反过来和原串一样,就称作"反对称"字符串.比如00001111和010101就是反对称的,100 ...

  4. lock to deteck in oracle

    0,5,10 0-23 * * * /home/oracle/utility/blocker/detect_blocker.sh db 120 > /home/oracle/utility/tr ...

  5. jQuery select年月日(生日)选择器

    实际项目中,在用户的个人中心,编辑用户资料时经常会遇到选择生日选项的问题. 因为我项目工程中没有使用如jQuery UI的插件性下拉列表,所以选择select + option的原生方式,实现选择器. ...

  6. jquery基础知识点总结

    Jquery是一个优秀的js库,它简化了js的复杂操作,不需要关心浏览器的兼容问题,提供了大量实用方法. Jquery的写法 方法函数化 链式操作 取值赋值合体] $(“p”).html();   取 ...

  7. filter 过滤器加载流程

    过滤器例子 <!--A过滤器--><filter> <filter-name>mdamptRightLimitFilter</filter-name> ...

  8. spark 学习路线及参考课程

    一.Scala编程详解: 第1讲-Spark的前世今生 第2讲-课程介绍.特色与价值 第3讲-Scala编程详解:基础语法 第4讲-Scala编程详解:条件控制与循环 第5讲-Scala编程详解:函数 ...

  9. windows 安装绿色版mysql

    (1)到官网下载绿色版mysql:http://dev.mysql.com/downloads/mysql/ (2)下载好后,放在F:\mysql,解压出来 (3)进入到mysql-5.6.19-wi ...

  10. 如何参与一个GitHub开源项目?

    如何参与一个GitHub开源项目? 摘要:本文是Github官如何参与一个GitHub开源项目方给出的参与Github上开源项目的一些指导,对希望加入开源社区的开发者是一个不错的参考. 最近一年开源项 ...