codeforces-344a magnets (Simulated question)

Source: Internet
Author: User

codeforces-344aMagnets
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 a poles, positive (a "plus") and negative (a "minus"). If the magnets is put together at a close distance, then the like Poles would repel each other and the opposite Poles would Attract each of the 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 what Mike puts the magnet on the table, it's either attracted to the previous one (forming a group of MULTIPL e magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous O NE). We assume 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 "", if Mike put the i-th magnet in the "Plus-minus" Position, or characters "ten", if Mike put the magnet in the "minus-plus" position.

Output

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

Sample Input

Input
6101010011010
Output
3
Input
401011010
Output
2

Hint

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

The second testcase has both groups, each consisting of the

Test instructions: give you a magnet in order, and where they are placed:

For example, I entered 01,10,01,10,10.

The resulting emissions of 01 10 01 10 10, wherein the same-sex repulsion, the opposite sex, the suction will be joined together to form a fast, so, the topic requires how many blocks.


#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, ncons t 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;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

codeforces-344a magnets (Simulated question)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.