zzu--2014年11月16日月潭赛 C称号
1230: Magnets
Time Limit: 1 Sec Memory Limit: 128 MB id=1230" style="color:rgb(26,92,200); text-decoration:none">Submit pid=1230" style="color:rgb(26,92,200); text-decoration:none">Web
Submit: 24 Solved: 13
[
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
Sample Output
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
题意:就是去求一堆磁铁能分成几段!
大水题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;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
zzu--2014年11月16日月潭赛 C称号的更多相关文章
- zzu--2014年11月16日月潭赛 B称号
1229: Rational Resistance Time Limit: 1 Sec Memory Limit: 128 MB Submit: 8 Solved: 4 [id=1229" ...
- 11月16日《奥威Power-BI基于SQL的存储过程及自定义SQL脚本制作报表》腾讯课堂开课啦
上周的课程<奥威Power-BI vs微软Power BI>带同学们全面认识了两个Power-BI的使用情况,同学们已经迫不及待想知道这周的学习内容了吧!这周的课程关键词—— ...
- 2016年11月16日 星期三 --出埃及记 Exodus 20:7
2016年11月16日 星期三 --出埃及记 Exodus 20:7 "You shall not misuse the name of the LORD your God, for the ...
- CSDN下载频道2014年11月4日本-5日常维护公告
尊敬的用户: CSDN于2005年推出了下载服务.经过数年的发展.下载频道的用户已经为无数用户提供了帮助,分享500万的技术资源. CSDN下载频道将于2014年11月4日23点至11月5日8点进行积 ...
- 2014年11月17~11月18日,杨学明老师《企业IT需求收集和实施》内训在湖南长沙某酒店成功举办!
2014年11月17至18日,受湖南某软件企业的邀请,杨学明老师<企业IT需求收集和实施>内训在某长沙某五星级酒店成功举办!来自全国各地的IT高管和企业负责人参加了此次培训.杨学明老师分别 ...
- 2014年5月16至24日,杨学明老师为深圳创维RGB事业部提供两天的《软件测试管理》内训服务!
2014年5月16日和24日,<在软件开发流程中构筑软件质量—软件测试管理>内训课程在深圳创维集团成功举办!来自创维研发.测试.生产等部门的管理人员和核心骨干等参加了此次培训,此次培训由研 ...
- 北京Uber优步司机奖励政策(11月16日~11月22日)
用户组:人民优步“关羽组”(适用于11月16日-11月22日)奖励政策: 滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/ ...
- OpenShare新功能@2014年11月 [2014-11-30]
新功能@Nov,2014 各门户层次主页布局自由编辑:升级为实时保存,这样用户编辑门户主页时,就算忘了点击“保存布局信息”,也不会丢失已做的工作 全方位支持匿名访问,支持构造公网以及extranet网 ...
- 2014年10月16号--for语句实例
Console.WriteLine("一对小兔一个月之后长成大兔,再过一个月后生新的一对兔子,且两年之后有多少对兔子,就是三兔子幼兔,小兔,成兔"); Console.WriteL ...
随机推荐
- petshop4.0 其中详细解释(系统架构)
前言:PetShop它是一个例子.微软用它来展示.Net容量企业系统开发.业界有很多.Net与J2EE争议.微软许多数据PetShop和Sun的PetStore从.这样的争论是不可避免的带有强烈的商业 ...
- Asp.net
视频摘要
Asp.net一遍又一遍视频最近,例如中,大多数的实现.由于原因的版本号,.当然学过是学过.总结不可缺少. 先宏观后微观.刚学完,感觉知识特别乱,所以先画了张图: watermark/2/text/a ...
- 用于编译cm-12.0 的 local_manifest.xml文件
将代码保存为 romservice.xml文件 <?xml version="1.0" encoding="UTF-8"?> <manifes ...
- Redis整合Spring结合使用缓存实例(转)
林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文介绍了如何在Spring中配置redis,并通过Spring中AOP的思想,将缓存的 ...
- HTML5_表单元素
<!DOCTYPE html> <hmtl> <html lang="zh-cn"> <head> <meta charse ...
- js右侧悬浮框
示例:屏幕右侧悬浮框 原理:oDiv.style.top = document.documentElement.clientHeight - oDiv.offsetHeight + scrollTop ...
- 认识Backbone (一)
Backbone.js为复杂WEB应用程序提供模型(models).集合(collections).视图(views)的结构.其中模型用于绑定键值数据和自定义事件:集合附有可枚举函数的丰富API: 视 ...
- 长方柱类【C++ 类定义】
Description 编写基于对象的程序,求长方柱(Bulk)的体积.数据成员包括长(length).宽(width).高(heigth).体积,要求用成员函数实现下面的功能: (1)由键盘输入长方 ...
- 使用Jfree实现吧条形图,java代码
使用Jfree实现吧条形图,java代码.它可能在生产的报告被常用,之后,主动生成自己的代码,可以随意查看.自由地配置图表的各种性质,为了达到他们的要求和目标 package test1; impor ...
- Android截图
Android截图很好的实现,从文档的发展,查看View有一个接口getDrawingCache(),这个接口可以得到View当调用这个接口的位图图像Bitmap. 抓取截图View在图像的某一个时刻 ...