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;
}

Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题的更多相关文章

  1. Codeforces Round #325 (Div. 2) A. Alena's Schedule 暴力枚举 字符串

    A. Alena's Schedule time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  3. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  4. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  5. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

  6. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

  7. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  8. Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题

    A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...

  9. Codeforces Round #384 (Div. 2) A. Vladik and flights 水题

    A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...

随机推荐

  1. c语言变量名称与变量

    0x00030 , 0x00031 ,0x00032 ,0x00033 是四个字节,用来存放0x00010(字母a的地址)

  2. bzoj1426

    偷个懒,转自hzwer [“这种煞笔题怎么总有人问”,被吧主D了... 用f[i]表示已经拥有了i张邮票,则期望还需要购买的邮票数 则f[n]=0 f[i]=f[i]*(i/n)+f[i+1]*((n ...

  3. poj3249

    显然是一道最短路径的题目,但是 1 ≤ n ≤ 100000, 0 ≤ m ≤ 1000000能轻松打爆dij+heap 怎么办? 挖掘题意,这是一个DAG图(有向无环图) 所以对于此类问题,我们有特 ...

  4. [POJ 2429] GCD & LCM Inverse

    GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10621   Accepted: ...

  5. jqGrid如何实现单选。

    设置如下:multiselect:true // multi-select checkboxes appear multiboxonly:true // checkboxes act like rad ...

  6. 文件I/O操作(2)

    lseek函数原型为int lseek(int fd,int offset, int whence),fd为定位文件的描述符,offset为偏移量,如果是正数,则向文件末尾偏移,负数时,则向文件头偏移 ...

  7. 自己手动写http服务器(2)

    tringBuilder response =new StringBuilder(); //1) HTTP协议版本.状态代码.描述 response.append("HTTP/1.1&quo ...

  8. HTTP 报文总结、外送两本电子书

    写在前面的话:喜欢这个比喻:如果说HTTP是因特网的信使,那么HTTP报文就是它用来搬东西的包裹. HTTP是一个应用层协议,研究它的内容的确很枯燥,没啥意思,都是规定好的,我们只需要知道是什么就好了 ...

  9. Hibernate学习笔记(四)关系映射之一对一关联映射

    一. 一对一关联映射 ²        两个对象之间是一对一的关系,如Person-IdCard(人—身份证号) ²        有两种策略可以实现一对一的关联映射 Ø        主键关联:即让 ...

  10. 【原创】lua的module的一些点

    lua的module好像是5.1开始有的 在xx.lua的开头写上 module('my_module') 这行等价于如下几行 local name = 'my_module' local M = { ...