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. 【java】实体类中 按照特定的字段 进行升序/降序 排序

    背景: 实际页面上  所有的分值都是按照JSON格式存储在一个字符串中 存储在同一个字段中: {"ownPTotal":"10>0","ownO ...

  2. Unity-EasyTouch插件之Two Finger

    今天,我们来学习下多手指触摸屏幕的事件,分别有挤压(缩放),挤压(旋转) 挤压(缩放): 在easytouch中,双手指挤压缩放的英文为Pinch 好了今天我们的测试是双手指挤压对物体进行缩放.我们测 ...

  3. go语言基础之基础数据类型 bool类型 浮点型

    1.bool类型 示例1: package main import "fmt" func main() { var a bool a = true fmt.Println(&quo ...

  4. vue-cli 配置路由之间跳转传递参数

    1.有2种方式去传参,如下代码: <template> <div> <div>这里是首页</div> <router-link :to=" ...

  5. KMP字符串模式匹配详解(zz)

    刚看到位兄弟也贴了份KMP算法说明,但本人觉得说的不是很详细,当初我在看这个算法的时候也看的头晕昏昏的,我贴的这份也是网上找的.且听详细分解: KMP字符串模式匹配详解 来自CSDN     A_B_ ...

  6. mysql5.7用户密码策略问题

    密码策略问题 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 查看 mysql 初 ...

  7. 【云计算】k8s相关资料

    参考资料: How to get started, and achieve tasks, using Kubernetes:http://kubernetes.io/docs/getting-star ...

  8. DataGridView绑定泛型List时,利用BindingList来实现增删查改

    DataGridView绑定泛型List时,利用BindingList来实现增删查改  一.   DataGridView绑定泛型List的种种 1.DataGridView数据绑定对比(DataTa ...

  9. [Tools] Unlock TypeScript's Features in Vanilla JS with @ts-check and JSDoc

    TypeScript can help you with your plain JavaScript files if you add a simple //@ts-check comment. Th ...

  10. 程序的入口及AppDelegate窗体显示原理

    AppDelegate.m - (void)dealloc { [_window release]; [super dealloc]; } - (BOOL)application:(UIApplica ...