您的位置:首页 > 其它

CodeForces 344A Magnets

2015-08-11 10:51 453 查看
A. Magnets

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

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

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.

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<stdlib.h>
#include<algorithm>
#define LL __int64
using namespace std;
int main()
{
int n;
scanf("%d",&n);
int pre=-1,num,ans=0;
for(int i=0;i<n;i++)
{
scanf("%d",&num);
if(pre==-1) {pre=num;ans++;continue;}
if(pre==10 && num==1) {ans++;pre=1;}
if(pre==1 && num==10) {ans++;pre=10;}
}
printf("%d\n",ans);
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: