Description
n 块磁铁排成一排,磁铁有两种状态,01和10分别表示正极的不同方向,问最后这些磁铁会变成几段
Input
第一行一整数
Output
输出这些磁铁最后会分成多少段
Sample Input
6
10
10
10
01
10
10
Sample Output
3
Solution
水题,只要相邻两个磁铁的状态不用则段数加一
Code
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
int n,a[maxn];
int main()
{
while(~scanf("%d",&n))
{
int num=1;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=2;i<=n;i++)if(a[i]!=a[i-1])num++;
printf("%dn",num);
}
return 0;
}
最后
以上就是香蕉人生最近收集整理的关于CodeForces 344 A.Magnets(水~)的全部内容,更多相关CodeForces内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复