Codeforces 344A Magnets
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-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.
Sample Input
6
10
10
10
01
10
10
3
4
01
01
10
10
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.
题意:给你一个数n,表示接下来会有n行 01或者 10,0表示磁极的正级,1,表示磁极的负极,目的是让你把这n个01或者10连接成一个字符串,判断这个字符串有多少快组成,也就是说有多少各连续的1,1或者0,0把这个长串分成了几个部分。。。
分析: 简单模拟,瞎搞。
code:
/*************************************************************************
> File Name: cf.cpp
> Author: PrayG
> Mail:
> Created Time: 2016年07月10日 星期日 12时57分34秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
#include<string>
using namespace std;
const int maxn = ;
string arr;
int main()
{
string str;
int n,ans= ;
cin >> n;
for(int t = ; t <= n; t++)
{
str.clear();
cin >> str;
if(t == )
{
arr += str;
}
else
{
int len = arr.length();
// printf("len = %d\n",len);
// cout <<"str = " << str << endl;
if(arr[len-] == str[])
{
//cout << "arr = " << arr << endl;
ans++;
}
arr += str;
}
}
cout << ans << endl;
return ;
}
Codeforces 344A Magnets的更多相关文章
- CodeForces - 344A Magnets (模拟题)
CodeForces - 344A id=46664" style="color:blue; text-decoration:none">Magnets Time ...
- Codeforces Round #330 (Div. 1) C. Edo and Magnets 暴力
C. Edo and Magnets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/pr ...
- codeforces Magnets
link:http://codeforces.com/contest/344/problem/A 这道题目很简单. 把输入的01 和10 当做整数,如果相邻两个数字相等的话,那么就属于同一组,否则,就 ...
- Codeforces 1345 D - Monopole Magnets
传送门:D. Monopole Magnets 这一场也是很神奇了,先是推迟三天,后是评测鸡崩了,unrated... 题意:每一行,每一列必须都要至少有一个s,n要可以到所有的黑格,n的上下左右如果 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
随机推荐
- 紫书 例题 11-3 UVa 1151 (有边集的最小生成树+二进制枚举子集)
标题指的边集是说这道题的套餐, 是由几条边构成的. 思路是先做一遍最小生成树排除边, 因为如果第一次做没有加入的边, 到后来新加入了很多权值为0的边,这些边肯定排在最前面,然后这条边的前面的那些边肯定 ...
- iOS技术栈-Swift版
在网上没找到基于Swift的技术栈介绍,或者技术已经不适用,所以自己画了一个,后面的博客中会重新整理基于Swfit的UI控件介绍和常用第三方库地图
- centos6.5安装配置nginx+php+mysql+httpsqs+ttserver+redis
一.准备 1.nginx, http://nginx.org/download/nginx-1.5.12.tar.gz 2.pcre, ftp://ftp.csx.cam.ac.uk/pub/soft ...
- 时间就是金钱HNCOI2000(最短路)
时间就是金钱HNCOI2000 版权声明:本篇随笔版权归作者YJSheep(www.cnblogs.com/yangyaojia)所有,转载请保留原地址! 人们总是选时间最短或费用最低的路线 例如, ...
- 【Android】资源系列(二) -- 文件原样保留的资源assets和res/raw文件夹
这两个文件夹都能够存放文件.而在打包的时候被原样保留. 那用这两个文件夹可以做什么事呢? 1.放一个apk,要用的时候调出来.免得去下载server下载. 2.放一个sql,当app数据库非常大的时候 ...
- 微信公众号开发将war包导入新浪sae出现错误
JAVA_Error: Error for /wechat.do java.lang.NoSuchFieldError: INSTANCE at org.apache.http.impl.io.Def ...
- 上传canvas图片到服务器
canvas绘图后用 canvasDom.toDataURL()可以得到png格式图片的base64 dataURI 然后用ajax post给后台 ,后端程序把开头的data:image/png; ...
- HDU 3652 B-number(数位dp&记忆化搜索)
题目链接:[kuangbin带你飞]专题十五 数位DP G - B-number 题意 求1-n的范围里含有13且能被13整除的数字的个数. 思路 首先,了解这样一个式子:a%m == ((b%m)* ...
- ThinkPHP5中find()和select()区别
ThinkPHP5中find()和select()区别 读取数据是指读取数据表中的一行数据(或者关联数据),主要通过find方法完成,例如: 1 2 3 4 $User = M("User& ...
- View简介
1.View 是所有widget类的基类 2.View的坐标 根据上面的图应该会比较容易明白,图中屏幕上放了一个ViewGroup布局,里面有个View控件 getTop:获取到的,是view自身的顶 ...