Magnets

简介: Magnets

文章目录

一、Magnets

总结


一、Magnets

本题链接:Magnets


题目:

A. Magnets

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

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.

image.png

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.


Examples

input

6

10

10

10

01

10

10

output

3

input

4

01

01

10

10

output

2

Note

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.


本博客给出本题截图:

image.png

image.png

题意:同性相斥,异性相吸,给n0110数据,分别代表+--+,问最后有几组

AC代码

#include <iostream>
#include <string>
using namespace std;
const int N = 100010;
string a[N];
int res;
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i ++ ) 
        cin >> a[i];
    for (int i = 0; i < n - 1; i ++ )
        if (a[i][1] == '1' && a[i + 1][0] == '1' || a[i][1] == '0' && a[i + 1][0] == '0')
            res ++;
    cout << res + 1 << endl;
    return 0;
}

总结

水题,不解释


目录
相关文章
Anton and Danik
Anton and Danik
92 0
Anton and Danik
Translation
Translation
156 0
Translation
Wrong Subtraction
Wrong Subtraction
66 0
Wrong Subtraction
Nearly Lucky Number
Nearly Lucky Number
117 0
Nearly Lucky Number
|
人工智能 BI
Tram
Tram
104 0
Tram
|
12天前
|
存储 人工智能 弹性计算
阿里云弹性计算_加速计算专场精华概览 | 2024云栖大会回顾
2024年9月19-21日,2024云栖大会在杭州云栖小镇举行,阿里云智能集团资深技术专家、异构计算产品技术负责人王超等多位产品、技术专家,共同带来了题为《AI Infra的前沿技术与应用实践》的专场session。本次专场重点介绍了阿里云AI Infra 产品架构与技术能力,及用户如何使用阿里云灵骏产品进行AI大模型开发、训练和应用。围绕当下大模型训练和推理的技术难点,专家们分享了如何在阿里云上实现稳定、高效、经济的大模型训练,并通过多个客户案例展示了云上大模型训练的显著优势。
|
15天前
|
存储 人工智能 调度
阿里云吴结生:高性能计算持续创新,响应数据+AI时代的多元化负载需求
在数字化转型的大潮中,每家公司都在积极探索如何利用数据驱动业务增长,而AI技术的快速发展更是加速了这一进程。
|
7天前
|
并行计算 前端开发 物联网
全网首发!真·从0到1!万字长文带你入门Qwen2.5-Coder——介绍、体验、本地部署及简单微调
2024年11月12日,阿里云通义大模型团队正式开源通义千问代码模型全系列,包括6款Qwen2.5-Coder模型,每个规模包含Base和Instruct两个版本。其中32B尺寸的旗舰代码模型在多项基准评测中取得开源最佳成绩,成为全球最强开源代码模型,多项关键能力超越GPT-4o。Qwen2.5-Coder具备强大、多样和实用等优点,通过持续训练,结合源代码、文本代码混合数据及合成数据,显著提升了代码生成、推理和修复等核心任务的性能。此外,该模型还支持多种编程语言,并在人类偏好对齐方面表现出色。本文为周周的奇妙编程原创,阿里云社区首发,未经同意不得转载。
|
12天前
|
人工智能 运维 双11
2024阿里云双十一云资源购买指南(纯客观,无广)
2024年双十一,阿里云推出多项重磅优惠,特别针对新迁入云的企业和初创公司提供丰厚补贴。其中,36元一年的轻量应用服务器、1.95元/小时的16核60GB A10卡以及1元购域名等产品尤为值得关注。这些产品不仅价格亲民,还提供了丰富的功能和服务,非常适合个人开发者、学生及中小企业快速上手和部署应用。
|
2天前
|
云安全 存储 弹性计算