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.

Sample Input

Input
6
10
10
10
01
10
10
Output
3
Input
4
01
01
10
10
Output
2

Hint

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.

题意:给你一个数n,表示接下来会有n行 01或者 10,0表示磁极的正级,1,表示磁极的负极,目的是让你把这n个01或者10连接成一个字符串,判断这个字符串有多少快组成,也就是说有多少各连续的1,1或者0,0把这个长串分成了几个部分。。。

分析: 简单模拟,瞎搞。

code:

 /*************************************************************************
> File Name: cf.cpp
> Author: PrayG
> Mail:
> Created Time: 2016年07月10日 星期日 12时57分34秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
#include<string>
using namespace std;
const int maxn = ;
string arr;
int main()
{
string str;
int n,ans= ;
cin >> n;
for(int t = ; t <= n; t++)
{
str.clear();
cin >> str;
if(t == )
{
arr += str;
}
else
{
int len = arr.length();
// printf("len = %d\n",len);
// cout <<"str = " << str << endl;
if(arr[len-] == str[])
{
//cout << "arr = " << arr << endl;
ans++;
}
arr += str;
}
}
cout << ans << endl;
return ;
}

Codeforces 344A Magnets的更多相关文章

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

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

  2. 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 ...

  3. codeforces Magnets

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

  4. Codeforces 1345 D - Monopole Magnets

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

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. 【BZOJ 1269】 [AHOI2006]文本编辑器editor

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] /* [move k] 指令.直接 把pos改成k.表示改变光标位置 [insert n s],在pos后面插入一个长度为n的字符串 ...

  2. 配置oh-my-zsh

    1. 当使用zsh进入庞大的git工程目录下时,会发生cd命令很慢的情况 可以把~/.oh-my-zsh/lib/git.zsh里面的git_prompt_info函数替换为 function git ...

  3. Obfuscating computer code to prevent an attack

    A method and system for obfuscating computer code of a program to protect it from the adverse effect ...

  4. Qt之自定义布局管理器(QCardLayout)

    简述 手动布局另一种方法是通过继承QLayout类编写自己的布局管理器. 下面我们详细来举一个例子-QCardLayout.它由同名的Java布局管理器启发而来.也被称之为卡片布局,每个项目偏移QLa ...

  5. (三)ng-app的使用困惑和angularJS框架的自己主动载入

    ng-app是angular的一个指令,代表一个angular应用(也叫模块).使用ng-app或ng-app=""来标记一个DOM结点.让框架会自己主动载入.也就是说,ng-ap ...

  6. vim 插件之vim-trailing-whitespace

    vim-trailing-whitespace 这个插件是快速去掉文章行末的空格 地址 http://github.com/bronson/vim-trailing-whitespace 如果你想要使 ...

  7. 网络通信-ping命令

  8. kali 2.0 linux中的Nmap的操作系统扫描功能

    不多说,直接上干货! 可以使用-O选项,让Nmap对目标的操作系统进行识别. msf > nmap -O 202.193.58.13 [*] exec: nmap -O 202.193.58.1 ...

  9. asp.net 项目发布注意点

    在修改了某些代码后,要发布到服务器 这时候 ,在本地发布完把对应的文件复制到服务器上覆盖即可. 1.如果修改的是.cs  .asmx等文件,则需要覆盖其对应项目名称的.dll文件 2.如果修改的是.h ...

  10. OnClientClick知识+一个上传的例子

    文件名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp ...