CF344A.Magnets

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

疯狂科学家迈克通过排列多米诺骨牌来娱乐自己。不过,他实际上并不需要真正的多米诺骨牌:他使用的是矩形磁铁。每块磁铁都有两个磁极——正极(“+”)和负极(“−”)。当两块磁铁彼此靠近放置时,同性磁极相互排斥,异性磁极相互吸引。

迈克首先将一块磁铁水平放置在桌面上。在随后的每一步中,迈克都在当前磁铁行的最右端再水平添加一块磁铁。根据迈克放置磁铁的方式,新磁铁可能被前一块磁铁吸引(从而与之连接,形成由多块磁铁组成的连通组),也可能被前一块磁铁排斥(此时迈克会将这块磁铁放在前一块磁铁右侧一段距离处)。我们约定:一块未与其他磁铁连接的孤立磁铁自身构成一个独立的组。

迈克已将若干磁铁排成一行。请确定这些磁铁共形成了多少个组。

输入格式

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.

输入的第一行包含一个整数 nn(1≤n≤1000001 \leq n \leq 100000)——磁铁的数量。接下来有 nn 行。第 ii 行(1≤i≤n1 \leq i \leq n)包含字符串 "01"(若 Mike 将第 ii 块磁铁放置为“正-负”方向),或字符串 "10"(若 Mike 将该磁铁放置为“负-正”方向)。

输出格式

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

在输出的单行中打印磁铁组的数量。

输入输出样例

  • 输入#1

    6
    10
    10
    10
    01
    10
    10

    输出#1

    3
  • 输入#2

    4
    01
    01
    10
    10

    输出#2

    2

说明/提示

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.

第一个测试用例对应于该图。该测试用例包含三组磁铁,各组分别由三个、一个和两个磁铁组成。

第二个测试用例包含两组磁铁,每组均由两个磁铁组成。

输入解题思路,AI测评打分。不知道怎么写?

首页