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. 通过OpenVPN来穿越上网(未实践)

    说明: 1.其实OpenVPN可以通过其实现穿越来上网,即全部请求都经过OpenVPN来处理.其原理是iptables转发.如果全程走iptables也是可以的,网上的教程基本都是基于iptables ...

  2. MongoDB 刷新几次就报错

    官方: MongoDB.Driver 在页面上 速度刷新几次,就会抛错? 为何? Service 层  Autofac

  3. 回顾苹果操作系统Mac OS的发展历史

    在新的MacBook AIR和Mac OS X Lion即将发布之际,我们仅以此文向伟大的苹果和乔布斯致敬.并祝Apple教主乔布斯早日康复,长命百岁,千秋万载,一统苹果! Mac OS是指运行于苹果 ...

  4. unity stuck when building

    卡在 packaging assets 这里的话 把文件夹只读属性去掉 应用于子文件夹

  5. Vue使用中遇到问题汇总(一)32个

    1.安装一些需要编译的包:提示没有安装python.build失败等 因为一些 npm 的包安装需要编译的环境,mac 和 linux 都还好,大多都齐全 .window 用户依赖 visual st ...

  6. vue中watch的用法总结以及报错处理Error in callback for watcher "checkList"

    首先确认 watch是一个对象,一定要当成对象来用. 对象就有键,有值. 键:就是你要监控的那个家伙,比如说$route,这个就是要监控路由的变化,或者是data中的某个变量. 值可以是函数:就是当你 ...

  7. from表单实现无跳转上传文件,接收页面后台数据

    实现无跳转发送表单数据.文件,并能接收后台返回的数据. 主要技术要点: 1.form表单添加target属性,指定一个iframme的name:form表单提交后在iframe内嵌窗口接受响应,主页面 ...

  8. 《javascript高级程序设计》读书笔记(四)引用类型

    第五章:引用类型 Object类型 创建object实例的两种方式: 1.new方式 var person = new Object(); person.name = "haozk" ...

  9. Maven Web项目配置Mybatis

    一.添加Mybatis和数据库相关的包 1 pom.xml中添加的包有mybatis,mybatis-spring,druid,MySQL-connector-Java,commons-io,refl ...

  10. 转:Android 签名验证机制(相当不错,强烈推荐)

    转:  http://riusksk.blogbus.com/logs/272154406.html Android应用签名验证过程中,满足以下条件才能安装应用: 1.SHA-1(除META-INF目 ...