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.
View Code
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
相关文章推荐
- MySQL出现同步延迟如何解决?优化?
- apache的扩展模块安装
- hdu 2795(单点修改)
- 检测CPU利用率的Shell脚本
- Num 31 : HDOJ : 1863 畅通工程 [ kruskal( 克鲁斯卡尔 )算法 ] [ 最小生成树 ]
- X的追求道路 SDUT 3027
- hdoj 1863 畅通工程 【最小生成树】
- 21-IO流-15-IO流(字符流-缓冲区-复制文本文件)
- 21-IO流-16-IO流(字符流-缓冲区-自定义MyBufferedReader-read方法)
- 本地推送的使用方法
- 手机端开发
- 浅析Android的横竖屏切换
- hdu 4109(拓扑排序 关键路径)
- SSL心跳漏洞的检测
- IOS开发 @property中assign、copy 、retain等关键字的理解
- 算法竞赛入门经典: 第三章 数组和字符串 3.3蛇形填数
- 21-IO流-14-IO流(字符流-缓冲区-BufferedReader-readLine方法原理)
- Oracle 12C -- Invisible Columns
- Error: L6218E: Undefined symbol main (referred from entry9a.o).
- Algorithms-94.Binary Tree Inorder Traversal