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 Input6101010011010 Output3 Input401011010 Output2
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;}
|