A. Alena's Schedule

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/586/problem/A

Description

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.

​i​​,C​i​​,即此题的初始分值、每分钟减少的分值、dxy做这道题需要花费的时间。

Output

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

Sample Input

5
0 1 0 1 1

Sample Output

4

HINT

题意

有人要去上课,1代表有课,0代表没课

这个人在有两个及以上连续的没课的时候,才会回家

然后问你这个人得在学校呆多久

题解:

直接暴力扫一遍就好了

有课会呆在学校,没课但是,上下都是课的,也会呆在学校

代码:

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

最新文章

  1. airline 設定 安裝
  2. background和background-size
  3. [转] Android获取Manifest中&lt;meta-data&gt;元素的值
  4. php大力力 [023节]CREATE TABLE创建新表sql写字段备注(2015-08-27)
  5. 如何利用jQuery进行简单表单验证
  6. 项目分析(PLUG)
  7. elasticsearch常用的插件
  8. 如何获取jqGrid中选择的行的数据
  9. SQL server 和Oracle 序列
  10. atan(正切函数)
  11. 【转载】设置event.cancelBubble,使触发子元素的onclick不同时触发父元素的onclick
  12. js this [转]
  13. 如何A掉未来程序改
  14. ASP.NET MVC扩展点
  15. AVL树之 Java的实现
  16. MySql 动态语句
  17. 连接mysql用mysql_connect不能连接
  18. web-hacking
  19. 同时安装anaconda2和anaconda3
  20. yield与递归的组合运用

热门文章

  1. Android开发之注解式框架ButterKnife的使用
  2. 解决windows下vim方向键变成 ABCD 的问题
  3. UVa 1363 (数论 数列求和) Joseph&#39;s Problem
  4. BZOJ2542: [Ctsc2001]终极情报网
  5. andori 动画验证必填项
  6. C#实现无物理边距真正可打印区域的绘图\打印程序开发
  7. POJ 2352 Stars
  8. [OFBiz]简介 二
  9. 使用 EasyBCD 安装Ubuntu 14.04 Error 15: file not found错误的解决方法
  10. sprintf的缓冲区溢出