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 1191】[HNOI2006]超级英雄Hero

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二分图的最大匹配. 因为要答下一题,这一题必须先答完. 所以如果某道题没有匹配了. 那么就直接break掉. [代码] #inclu ...

  2. 国庆 day 2 上午

    一道图论神题(god) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,只有 ...

  3. Node.js使用cnpm

    npm是Node.js中维护第三方库.模块的工具,可是国外的速度非常悲剧,这里有一个中国的源cnpm. http://cnpmjs.org/ 须要在命令行中执行 npm install -g cnpm ...

  4. 从一次生产事故说起——linux的单用户模式,救援模式等等

    伴随着今年linux上面最大一个安全漏洞bash漏洞的出现,我们公司也開始了风风火火的漏洞修复工作,机器一多,也就easy出问题,有台64位的linuxserver一不小心就升级了32位 bash 的 ...

  5. 开源 java CMS - FreeCMS2.3会员个人资料

    原文地址:http://javaz.cn/site/javaz/site_study/info/2015/28577.html​ 项目地址:http://www.freeteam.cn/ 个人资料 从 ...

  6. Linux 文件系统初步

         在Linux系统中,假设我们想要知道一个文件的详细信息,那么最简便的方法自然就是ls命令了.例如以下图所看到的:当在shell输入命令"ls -l old"时,在下方就会 ...

  7. Vim 删除不包含指定字符串的行及统计匹配个数

    Vim 删除不包含指定字符串的行及统计匹配个数 转载▼     Help :g/pattern/d 是找到pattern, 删之 :v/pattern/d 是找到非pattern, 删之 :%s/xx ...

  8. nyoj--218--Dinner(语法)

    Dinner 时间限制:100 ms  |  内存限制:65535 KB 难度:1 描述 Little A is one member of ACM team. He had just won the ...

  9. hdoj--1005--Number Sequence(规律题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  10. tomcat和nginx相互结合的优化调整

    在工作中遇到这样的情况 Tomcat为后台 nginx为反向代理 需要往后台导入数据,由于处理时间过长,导致访问时出现504和500  通过修改tomcat中maxParameterCount=&qu ...