Problem description

Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.

Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.

Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 100000) — the number of magnets. Then n lines follow. The i-th line (1 ≤ i ≤ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.

Output

On the single line of the output print the number of groups of magnets.

Examples

Input

6
10
10
10
01
10
10

Output

3

Input

4
01
01
10
10

Output

2

Note

The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.

The second testcase has two groups, each consisting of two magnets.

解题思路:很简单的一道题,就是求能分出多少块整体。做法:将其转化成字符串,从第三个字符开始,统计str[i]==str[i-1]的个数即为整体分成块的个数,水过!

AC代码:

 #include<bits/stdc++.h>
using namespace std;
int main(){
int n,num=;string str="",r;
cin>>n;getchar();
while(n--){cin>>r;str+=r;}
for(unsigned int i=;i<str.length();i+=)
if(str[i]==str[i-])num++;
cout<<num<<endl;
return ;
}

B - Magnets的更多相关文章

  1. Codeforces Round #330 (Div. 1) C. Edo and Magnets 暴力

    C. Edo and Magnets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/pr ...

  2. CodeForces - 344A Magnets (模拟题)

    CodeForces - 344A id=46664" style="color:blue; text-decoration:none">Magnets Time ...

  3. Codeforces 344A Magnets

    Description Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dom ...

  4. Codeforces 1345 D - Monopole Magnets

    传送门:D. Monopole Magnets 这一场也是很神奇了,先是推迟三天,后是评测鸡崩了,unrated... 题意:每一行,每一列必须都要至少有一个s,n要可以到所有的黑格,n的上下左右如果 ...

  5. codeforces Magnets

    link:http://codeforces.com/contest/344/problem/A 这道题目很简单. 把输入的01 和10 当做整数,如果相邻两个数字相等的话,那么就属于同一组,否则,就 ...

  6. [cf1491F]Magnets

    首先,只需要找到一个有磁性的位置,就可以通过$n-1$次判断其余磁铁是否有磁性,因此也就是要在$\lfloor\log_{2}n\rfloor+1$次中找到一个有磁性的位置 有一个$n-1$次的做法, ...

  7. CodeForces Round 200 Div2

    这次比赛出的题真是前所未有的水!只用了一小时零十分钟就过了前4道题,不过E题还是没有在比赛时做出来,今天上午我又把E题做了一遍,发现其实也很水.昨天晚上人品爆发,居然排到Rank 55,运气好的话没准 ...

  8. Qt Examples Qt实例汇总

    ActiveQt Examples Using ActiveX from Qt applications. Animation Framework Examples Doing animations ...

  9. 12 Tips for Accurate Project Estimating

    Projects typically involve many dynamic aspects, yet they're often constrained by finite conditions. ...

随机推荐

  1. 【转载】resolv.conf中search作用

    原文地址:http://www.oliver.ren/linux/387.html reslov.conf中的search主要是用来补全hostname的,有时候域名太长,可以做一个短域名做主机名字, ...

  2. POJ3984——迷宫问题

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31616   Accepted: 18100 Descriptio ...

  3. HTML解析库BeautifulSoup4

    BeautifulSoup 是一个可以从HTML或XML文件中提取数据的Python库,它的使用方式相对于正则来说更加的简单方便,常常能够节省我们大量的时间. BeautifulSoup也是有官方中文 ...

  4. KD树学习小结

    几个月后的UPD: 学习完下面之后,实战中的总结: 0.比赛中正解就是kdtree的题目很少很少 1.几类优先考虑kdtree的题目: k(维度) >= 3 的题目 二维平面上涉及区间标记的题目 ...

  5. Maven学习总结(2)——Maven项目构建过程练习

    Maven学习总结(二)--Maven项目构建过程练习 上一篇只是简单介绍了一下maven入门的一些相关知识,这一篇主要是体验一下Maven高度自动化构建项目的过程 一.创建Maven项目 1.1.建 ...

  6. Android第三方开源下拉框:NiceSpinner

     Android第三方开源下拉框:NiceSpinner Android原生的下拉框Spinner基本上可以满足Android开发对于下拉选项的设计需求,但现在越来越流行的下拉框不满足于Andro ...

  7. [HZOJ10420]计算

    [HZOJ10420]计算 题目 给定一个数列,第i个位置包含两个数ai,bi 每次询问给出x,y 求数列ai*x+bi*y的最大值 输入所有数为自然数,在int范围内 INPUT 第一行为n,m.n ...

  8. [bzoj1923]外星千足虫[高斯消元]

    高斯消元解异或方程组 #include <iostream> #include <algorithm> #include <cstdio> #include < ...

  9. [Bzoj3940] [AC自动机,USACO 2015 February Gold] Censor [AC自动机模板题]

    AC自动机模板题(膜jcvb代码) #include <iostream> #include <algorithm> #include <cstdio> #incl ...

  10. PatentTips - Substitute virtualized-memory page tables

    BACKGROUND Many computer systems utilize virtualized memory for security, stability and/or other pur ...