Codeforces 465B Inbox (100500)
来源:互联网 发布:现在淘宝最新版本 编辑:程序博客网 时间:2024/06/05 10:52
题意:
给你n个0,1的数,1表示有信未读。现给出一些操作,问你最少需要多少操作才能读完所有未读的信。
思路:
贪心。有信没读就进去读,读完一排连续的信后,才跳出list去找下一排未读的信。即统计下有几个1和几个1的连续区间-1就是答案。
#include<cstdio>const int MAX=1005;int n,a[MAX];int main(){scanf("%d",&n);int ans=0;for(int i=1;i<=n;i++){scanf("%d",&a[i]);ans+=a[i];}int num=0;bool flag=true;for(int i=1;i<=n;i++){if(a[i]&&flag) num++,flag=false;else if(a[i]==0) flag=true;}printf("%d\n",ans+num-(num==0?0:1));return 0;}
0 0
- [Codeforces] 465B - Inbox (100500)
- Codeforces 465B Inbox (100500)
- 【CODEFORCES】 B. Inbox (100500)
- codeforces-#465B. Inbox (100500)(模拟)
- Codeforces 465B Inbox (100500)(水题)
- Codeforces Round #265 (div2) B. Inbox (100500)
- Codeforces Round #265 (Div. 2) B. Inbox (100500)(模拟)
- Codeforces Round #265 (Div. 2) B. Inbox (100500)
- B. Inbox (100500)
- Inbox (100500)
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- FatMouse' Trade<hdoj1009>
- 【JVM】——简单入门之内部组成
- 【一】Deep learning简介
- 产品助理day11以及支付宝支付和微信支付的对比
- Qt获取文件信息
- Codeforces 465B Inbox (100500)
- 从上往下打印二叉树
- linux关机/重启命令
- php核心知识点(总结)
- 字符串查找最长子串
- 随想-如何成为出色的程序员
- PAT-1002
- 通向架构师的道路(第一天)之Apache整合Tomcat
- 九大排序算法再总结