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;
}

总结

水题,不解释


目录
相关文章
|
8月前
|
传感器 自动驾驶 算法
《反事实棱镜:折射因果表征学习的深层逻辑》
反事实分析是一种探究“如果……会怎样”问题的思维方式,在日常生活和科学研究中均有重要应用。它通过构建与现实不同的假设情境,揭示变量间的因果关系。在因果表征学习中,反事实分析帮助理解模型决策路径、评估泛化能力、优化模型性能,并增强可解释性和可信度。例如,在医疗诊断中,它可辅助医生评估病情和治疗方案;在自动驾驶领域,它能模拟危险场景以提升系统安全性。尽管实际应用面临复杂系统的挑战,但反事实分析为突破困境提供了有力工具,推动因果表征学习在多领域中的深入应用。
111 2
|
消息中间件 存储 运维
线上环境大规模RocketMQ集群不停机优雅升级实践
线上环境大规模RocketMQ集群不停机优雅升级实践
线上环境大规模RocketMQ集群不停机优雅升级实践
|
程序员 测试技术 Docker
黑马程序员2024最新SpringCloud微服务开发与实战 个人学习心得、踩坑、与bug记录Day3 全网最全
黑马程序员2024最新SpringCloud微服务开发与实战 个人学习心得、踩坑、与bug记录Day3 全网最全(1)
1851 1
|
负载均衡 网络协议 前端开发
一文快速上手 Nacos 注册中心+配置中心!
一文快速上手 Nacos 注册中心+配置中心!
9085 0
|
消息中间件 存储 缓存
Kafka万亿级消息实战
Kafka万亿级消息实战
|
Shell 网络安全 Linux
Expect 安装 on centos7
使用场景 在主机A上编写并且执行Shell脚本,Shell脚本中需要ssh到主机B上执行交互命令。 安装 在主机A上安装expect: yum install expect Shell脚本示例 #!/usr/bin/expect set ip 192.
1657 0
|
Linux Android开发
Linux/Android——input_handler之evdev (四) 【转】
转自:http://blog.csdn.net/u013491946/article/details/72638919 版权声明:免责声明: 本人在此发文(包括但不限于汉字、拼音、拉丁字母)均为随意敲击键盘所出,用于检验本人电脑键盘录入、屏幕显示的机械、光电性能,并不代表本人局部或全部同意、支持或者反对观点。
1474 0
|
4天前
|
云安全 人工智能 算法
以“AI对抗AI”,阿里云验证码进入2.0时代
三层立体防护,用大模型打赢人机攻防战
1315 4