Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.

Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens).
In one click he can do any of the following operations:

  • Move from the list of letters to the content of any single letter.
  • Return to the list of letters from single letter viewing mode.
  • In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.

The program cannot delete the letters from the list or rearrange them.

Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox.

The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The
i-th number equals either
1, if the i-th number is unread, or
0, if the i-th letter is read.

Output

Print a single number — the minimum number of operations needed to make all the letters read.

Sample test(s)
Input
5
0 1 0 1 0
Output
3
Input
5
1 1 0 0 1
Output
4
Input
2
0 0
Output
0
题意:查看邮件,求须要操作的次数
思路:题意题,模拟
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int main() {
int n, num[1010];
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &num[i]);
int ans = 0;
for (int i = 0; i < n; i++)
if (num[i] && num[i+1])
ans++;
else if (num[i] && !num[i+1])
ans += 2;
if (!num[n] && ans)
ans--;
else if (num[n])
ans++;
printf("%d\n", ans);
return 0;
}

Codeforces Round #265 (Div. 2) B. Inbox (100500)的更多相关文章

  1. Codeforces Round #265 (Div. 2)

    http://codeforces.com/contest/465 rating+7,,简直... 感人肺腑...............蒟蒻就是蒟蒻......... 被虐瞎 a:inc ARG 题 ...

  2. Codeforces Round #265 (Div. 1) C. Substitutes in Number dp

    题目链接: http://codeforces.com/contest/464/problem/C J. Substitutes in Number time limit per test 1 sec ...

  3. Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子

    http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,如今要求输出一个字典比s大的字符串,且串中字母在一定 ...

  4. Codeforces Round #265 (Div. 2) E. Substitutes in Number

    http://codeforces.com/contest/465/problem/E 给定一个字符串,以及n个变换操作,将一个数字变成一个字符串,可能为空串,然后最后将字符串当成一个数,取模1e9+ ...

  5. Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断

    http://codeforces.com/contest/465/problem/D 给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值.问说8个点是否可以组成立方体. 暴力枚举即可, ...

  6. Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串

    http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,现在要求输出一个字典比s大的字符串,且串中字母在一定 ...

  7. Codeforces Round #265 (Div. 2) D. Restore Cube 立方体推断

    http://codeforces.com/contest/465/problem/D 给定8个点坐标.对于每一个点来说,能够任意交换x.y,z坐标的数值. 问说8个点能否够组成立方体. 暴力枚举就可 ...

  8. Codeforces Round #265 (Div. 2) E

    这题说的是给了数字的字符串 然后有n种的操作没次将一个数字替换成另一个字符串,求出最后形成的字符串的 数字是多大,我们可以逆向的将每个数推出来,计算出他的值和位数记住位数用10的k次方来记 1位就是1 ...

  9. Codeforces Round #265 (Div. 1)

    D. World of Darkraft - 2 time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. 使用Python SocketServer快速实现多线程网络服务器

    Python SocketServer使用介绍 1.简介: SocketServer是python的一个网络服务器框架,可以减少开发人员编写网络服务器程序的工作量. SocketServer总共有4个 ...

  2. JavaScript 时间与日期处理实战:你肯定被坑过

    本部分的知识图谱请参考编程语言知识图谱-时间与日期. 本文JavaScript 时间与日期处理实战:你肯定被坑过从属于笔者的Web 前端入门与最佳实践中 JavaScript 入门与最佳实践系列文章. ...

  3. .Net 有关程序集查找与加载的一点反思

    最近在做一款叫VICA产品,此产品采用了插件机制,插件在运行中加载,插件与插件之间存在依赖关系,所有的插件DLL为方便管理都放置在Plugins的文件夹下统一管理.这种处理方式不自觉的就让我想了解cl ...

  4. asp.net core 1.0初识

    本文将对微软下一代ASP.NET框架做个概括性介绍,方便大家进一步熟悉该框架. 在介绍ASP.NET Core 1.0之前有必要澄清一些产品名称及版本号.ASP.NET Core1.0是微软下一代AS ...

  5. Mac DBeaver Client home is not specified for connection解决办法

    问题: 一般出现这个问题是由于DBeaver 程序无法自动找到数据库的安装目录,在进行数据的导入导出时无法执行,这是因为执行指令需要数据库相关命令的支持. 解决办法: 我用的是mysql,这里拿mys ...

  6. 版本控制SVN的使用笔记

    安装 客户端和服务端下载地址,打开网址,根据自己的操作系统下载对应的版本,window用户服务端一般安装的是VisualSVN,客户端安装TortoiseSVN,在实际工作中,我们一般只需要安装Tor ...

  7. jquery ajax 不执行赋值,return没有返回值的解决方法

    大家先看一段简单的jquery ajax 返回值的js 复制代码 代码如下: function getReturnAjax{ $.ajax({ type:"POST", url:& ...

  8. iOS:UIResponser控件的介绍(响应者)

    UIResponser响应者控件   知识: 在iOS中不是任何对象都能处理事件,只有继承了UIResponser的对象才能接收并处理事件.我们称之为“响应者对象” UIApplication,UIV ...

  9. linux CMakeLists.txt 语法

    CMake入门教程 参考文献:http://www.ibm.com/developerworks/cn/linux/l-cn-cmake/index.html 官方网址:http://www.cmak ...

  10. linux下软件的更新命令

    linux下软件的更新命令   在ubuntu服务器下安装包的时候,经常会用到sudo apt-get install 包名 或 sudo pip install 包名,那么两者有什么区别呢? 1.区 ...