zzu--2014年11月16日月潭赛 C称号

简介:

1230: Magnets

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 24   Solved: 13
[ Submit][ Status][ Web Board]

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 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.

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-thmagnet 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.

Sample Input

6
1 0
10
10
01
10
10
4
01
01
1 0
10

Sample Output

3
2

HINT

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.

Source

CF


题意:就是去求一堆磁铁能分成几段!


大水题AC代码:

#include <stdio.h>

int main()
{
    char a[3];
    int n;
    while(scanf("%d", &n) != EOF)
    {
                      scanf("%s", a);
                      n--;
                      char cur = a[1];
                      int ans=1;
                      while(n--)
                      {
                                scanf("%s", a);
                                if(a[0] == cur)
                                {
                                        ans++;
                                        cur = a[1];
                                }
                      }
                      printf("%d\n", ans);
    }
    return 0;
}




版权声明:本文博客原创文章,博客,未经同意,不得转载。


本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4632972.html,如需转载请自行联系原作者


相关文章
|
7月前
|
存储 算法 数据可视化
推荐一款多通道脑电图EEG采集仪
推荐一款多通道脑电图EEG采集仪
|
JavaScript
Ant Design Vue栅格Grid的使用
Ant Design Vue栅格Grid的使用
Ant Design Vue栅格Grid的使用
|
消息中间件 存储 Java
聊聊 Kafka: 在 Linux 环境上搭建 Kafka
聊聊 Kafka: 在 Linux 环境上搭建 Kafka
628 0
|
存储 编译器 测试技术
CppCheck的使用
CppCheck的使用
968 0
|
Java Linux 程序员
linux实现定时备份文件到百度网盘详细教程
作为一个程序员,数据备份尤为重要,本文主要介绍的是将服务器上的某文件定时备份到百度网盘中。主要实现思路是:安装pip、byp --&gt; 百度网盘进行授权登陆 --&gt; 使用crontab+bypy实现定时自动数据备份。
1801 0
|
缓存 负载均衡 网络协议
面试题22解析-CDN分析
题目:描述一下CDN的工作机制?
1558 0
|
9月前
|
机器学习/深度学习 算法 搜索推荐
《探秘Adagrad算法:自适应学习率的奥秘与适用场景》
Adagrad算法通过自适应调整学习率,根据参数梯度的累积平方动态改变每个参数的学习率。初始时设置学习率η,每次迭代计算梯度并累积其平方,更新后的学习率为η/√(r_t+ε),使频繁更新的参数学习率减小,稀疏参数学习率增大。适用于稀疏数据、特征重要性差异大、前期快速探索及简单模型场景。然而,学习率单调递减可能影响后期训练效果。
321 3
|
运维 负载均衡 数据库
为什么要使用微服务架构?
本文讨论了从传统单体架构到微服务架构的转变。单体架构将所有功能集成在一个代码库中,导致复杂性高、扩展性和维护困难。相比之下,微服务架构将大型应用拆分为独立服务,降低了耦合度,优点包括易于开发和维护、快速启动、按需伸缩和更强的稳定性。然而,微服务也带来了部署管理难度增加、分布式事务一致性问题和故障定位困难等挑战。为解决这些问题,推荐了.NET微服务框架Wing。
247 4
|
域名解析 Docker 容器
使用docker+ddns 实现动态域名解析
使用docker+ddns 实现动态域名解析
1992 8