A. Alena's Schedule
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.

One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).

The University works in such a way that every day it holds exactly n lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).

The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the n pairs she knows if there will be a class at that time or not.

Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.

Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.

Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of lessons at the university.

The second line contains n numbers ai (0 ≤ ai ≤ 1). Number ai equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers a1, a2, ..., an are separated by spaces.

Output

Print a single number — the number of pairs during which Alena stays at the university.

Examples
input
5
0 1 0 1 1
output
4
input
7
1 0 1 0 0 1 0
output
4
input
1
0
output
0
Note

In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.

In the last sample Alena doesn't have a single pair, so she spends all the time at home.

题意:从第一个‘1’ 开始计数 两个‘1’中最多有一个‘0’ 直到最后一个‘1’  统计这个序列的个数

题解:暴力

 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n;
int a[];
int ans;
int main()
{
scanf("%d",&n);
ans=;
int f=-;
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++)
{
if(a[i]==&&(i-f-)==)
ans++;
if(a[i]==)
{
ans++;
f=i;
} }
cout<<ans<<endl;
return ;
}

Codeforces Round #325 (Div. 2) A的更多相关文章

  1. Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid

    F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  2. Codeforces Round #325 (Div. 2) D. Phillip and Trains BFS

    D. Phillip and Trains Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/ ...

  3. Codeforces Round #325 (Div. 2) C. Gennady the Dentist 暴力

    C. Gennady the Dentist Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586 ...

  4. Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题

    A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/pr ...

  5. Codeforces Round #325 (Div. 2) B. Laurenty and Shop 前缀和

    B. Laurenty and Shop Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/p ...

  6. Codeforces Round #325 (Div. 2) Phillip and Trains dp

    原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. ...

  7. Codeforces Round #325 (Div. 2) Laurenty and Shop 模拟

    原题链接:http://codeforces.com/contest/586/problem/B 题意: 大概就是给你一个两行的路,让你寻找一个来回的最短路,并且不能走重复的路. 题解: 就枚举上下选 ...

  8. Codeforces Round #325 (Div. 2) Alena's Schedule 模拟

    原题链接:http://codeforces.com/contest/586/problem/A 题意: 大概就是给你个序列..瞎比让你统计统计什么长度 题解: 就瞎比搞搞就好 代码: #includ ...

  9. Codeforces Round #325 (Div. 2) D bfs

    D. Phillip and Trains time limit per test 1 second memory limit per test 256 megabytes input standar ...

  10. Codeforces Round #325 (Div. 1) D. Lizard Era: Beginning

    折半搜索,先搜索一半的数字,记录第一个人的值,第二个人.第三个人和第一个人的差值,开个map哈希存一下,然后另一半搜完直接根据差值查找前一半的答案. 代码 #include<cstdio> ...

随机推荐

  1. Nginx无法加载.woff .eot .svg .ttf等解决办法

    在Nginx的配置文件,加上以下代码即可修复该问题 location ~ \.(eot|otf|ttf|woff|svg)$ { add_header Access-Control-Allow-Ori ...

  2. select值改变

    改变select的值,然后执行一个方法.可以用chang: $("#select").change(function(){ //要执行的内容 });

  3. 指定的参数已超出有效值的范围。 参数名: site

    “/”应用程序中的服务器错误. 指定的参数已超出有效值的范围.参数名: site 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的 ...

  4. Makefile (2) gdb

    gdb调试 1.用debug的方式编译 -g 2.打上断点 3.单步调试 step into 进入函数里面 step over 运行整个函数 step return 跳出当前函数 4.继续运行 5.打 ...

  5. POJ:2139-Six Degrees of Cowvin Bacon

    传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...

  6. Android 时间计算工具 通用类TimeUtil

    1.整体分析 1.1.源代码如下,可以直接Copy. public class TimeUtil { private static final String TAG = "TimeUtil& ...

  7. Javascript Step by Step - 02

    DOM 操作 DOM是面向HTML和XML文档的API,为文档提供了结构化表示.在DOM中一切都是节点Node,文档就是由许多的Node组成的.文档里的每个节点都有属性 nodeName.nodeVa ...

  8. 遍历两个自定义列表来实现字典(key:value)

    #自定义key    ${keys}    create list    key1    key2    key3 #自定义value    ${values}    create list    v ...

  9. PhpStorm 格式化中花括号缩进方式

    格式化前: function func() { return ; } 格式化后: function func() { return ; } 在PhpStorm中的配置:File -> Setti ...

  10. Python 列表、元组、字典及集合操作详解

    一.列表 列表是Python中最基本的数据结构,是最常用的Python数据类型,列表的数据项不需要具有相同的类型 列表是一种有序的集合,可以随时添加和删除其中的元素 列表的索引从0开始 1.创建列表 ...