CF586A.Alena's Schedule
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
阿列娜已成功通过大学入学考试,现在正期待着开始大学学习。
在俄罗斯的大学中,一节持续两学时(每学时为45分钟)的课程传统上被称为“一节课”(pair)。
大学每天恰好安排 n 节课。根据某学生班级的具体课表,某一天中部分课程时段可能有课,而另一些则为空闲(这类空闲时段称为“课间休息”)。
大学官网已公布了阿列娜所在班级明天的课表。因此,对于这 n 节课中的每一节,她都已知该时段是否有课。
阿列娜家离大学较远,因此若遇到课间休息,她并不总是回家。仅当课间休息连续包含至少两节空闲课程时,她才有时间回家;否则,她会在大学等待下一节课。
当然,阿列娜不希望上课时犯困,因此她会尽可能多睡觉,仅在课表中第一节有课的课程时段才抵达大学。类似地,若当天再无后续课程,则阿列娜立即回家。
阿列娜十分珍惜在家的时间,因此只要有可能,她就一定会回家,并且仅在下一节课开始前才返回大学。请帮阿列娜计算:她总共将在大学停留多少节课的时段?注意:在某些课程时段中,阿列娜可能正待在大学中等待后续课程。
输入格式
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 a__i (0 ≤ a__i ≤ 1). Number a__i equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers _a_1, _a_2, ..., a__n are separated by spaces.
输入的第一行包含一个正整数 n(1 ≤ n ≤ 100)—— 表示大学中课程的节数。
第二行包含 n 个数字 ai(0 ≤ ai ≤ 1)。若 ai=0,表示阿莲娜第 i 节课没有课;否则(即 ai=1)表示她有课。数字 a1,a2,…,an 以空格分隔。
输出格式
Print a single number — the number of pairs during which Alena stays at the university.
输出一个整数——阿尔娜留在大学的配对次数。
输入输出样例
输入#1
5 0 1 0 1 1
输出#1
4
输入#2
7 1 0 1 0 0 1 0
输出#2
4
输入#3
1 0
输出#3
0
说明/提示
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.
在第一个样例中,阿莲娜从第二节到第五节课(含)一直待在学校,在第三节上课期间,她会在学校等待下一节课。
在最后一个样例中,阿莲娜没有任何一节课,因此她全程都待在家里。
输入解题思路,AI测评打分。不知道怎么写?