CodeForces - 344A

Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

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

题意:依照顺序给你一个个磁铁,以及他们放置的位置:

比方说输入了01,10,01。10,10

则形成的排放为01 10 01 10 10。当中同性相斥,异性相吸,相吸的会连在一起形成一个快。如此。题目要求出有多少个块。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define root 1, 1, N
const int MAXN = 5e4 + 5;
char op[2][5];
int n;
int main() {
scanf("%d", &n);
int cnt = 0;
for(int i = 0 ; i < n ; i ++) {
scanf("%s", op[0]);
if(i == 0) {
cnt ++;
strcpy(op[1], op[0]);
continue;
}
bool flag = true;
if(op[1][0] - op[0][1] != 0) {
flag = false;
}
strcpy(op[1], op[0]);
if(flag) cnt ++;
}
printf("%d\n", cnt);
return 0;
}

CodeForces - 344A Magnets (模拟题)的更多相关文章

  1. Codeforces 344A Magnets

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

  2. Codeforces 749C. Voting 模拟题

    C. Voting time limit per test: 1 second memory limit per test: 256 megabytes input: standard input o ...

  3. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  4. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  5. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  6. Codeforces Beta Round #7 B. Memory Manager 模拟题

    B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...

  7. Codeforces Beta Round #5 B. Center Alignment 模拟题

    B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...

  8. Codeforces Beta Round #3 C. Tic-tac-toe 模拟题

    C. Tic-tac-toe 题目连接: http://www.codeforces.com/contest/3/problem/C Description Certainly, everyone i ...

  9. Codeforces Gym 100269B Ballot Analyzing Device 模拟题

    Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...

随机推荐

  1. E20170829-mk

    Parse   vt. 从语法上描述或分析(词句等); serial    adj. 连续的; 连载的; 顺序排列的; 分期偿付的; MultiThread n. 多线程; 多流; concurren ...

  2. [Apple开发者帐户帮助]五、管理标识符(5)创建一个iCloud容器

    您必须拥有一个或多个iCloud容器才能启用iCloud. 所需角色:帐户持有人或管理员. 在“ 证书”,“标识符和配置文件”中,从左侧的弹出菜单中选择操作系统. 在“标识符”下,选择“iCloud容 ...

  3. springboot创建项目

    Springboot作为轻量级快速开发受到无数java人的青睐,Spring Boot是为了简化Spring应用的创建.运行.调试.部署等而出现的,使用它可以做到专注于Spring应用的开发,而无需过 ...

  4. 深入理解Redis(番外)——持久化

    引语 Redis作为一款内存数据库,自然所有数据都加载在内存中,那么自然就有小伙伴会问,如果服务器宕机了怎么办,数据不都丢了吗,不用担心,Redis早就提供了两种方式来将数据进行持久化,即便服务器宕机 ...

  5. SQL Server 一个简单的游标

    先看一下原表: DECLARE @id INT; DECLARE @name NVARCHAR(100); DECLARE c_department CURSOR FOR SELECT StuID, ...

  6. selenium获取页面通过样式隐藏获取不到元素解决方案

    如图更换图像这个按钮通过bottom:-30px隐藏了,通过如下代码获取不到页面元素,后台会报错 driver.findElement(By.className("js-avator-lin ...

  7. 范畴论-一个单子(Monad)说白了不过就是自函子范畴上的一个幺半群而已

    范畴即为结构:包含要素和转化. 范畴为高阶类型. 函子为高阶函数.函子的输入为态射.函子为建立在态射基础上的高阶函数.函子用于保持范畴间映射的结构.态射用于范畴内部的转换. 群为运算规则的约束. 自函 ...

  8. UNIX SOCKET编程简介

    1  .  Layered Model of Networking Socket  编程的层次模型如下图所示,   最上面是应用层,应用层下面的是  SOCKET API  层,再下面是传输层和网络层 ...

  9. 初识cocos creator的一些问题

    本文的cocos creator版本为v1.9.01.color赋值cc.Label组件并没有颜色相关的属性,但是Node有color的属性. //如果4个参数,在ios下有问题let rgb = [ ...

  10. 构造函数+原型的js混合模式

    function Parent(){ this.name = "李小龙"; this.age = "30"; };Parent.prototype.lev=fu ...