Alena's Schedule[水题]
来源:互联网 发布:阿里云 王坚 编辑:程序博客网 时间:2024/05/16 09:06
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.
Output
Print a single number — the number of pairs during which Alena stays at the university.
Sample Input
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
Hint
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.
#include<stdio.h>#include<string.h>#include<math.h>#include<queue>#include<vector>#include<algorithm>#define INF 0x3f3f3f3fusing namespace std;int a[120];int main(){ int n; scanf("%d",&n); for(int i=2;i<n+2;i++){ scanf("%d",&a[i]); } int cnt=0; for(int i=0;i<n+2;i++){ int j=i; for(;j<n+4;j++){ if(a[j]) break; } if(j-i>1) i=j-1; else cnt++; } printf("%d\n",cnt); return 0;}
- Alena's Schedule[水题]
- A. Alena's Schedule
- codeforces586A Alena's Schedule(模拟)
- Alena's Schedule(模拟)
- Codeforces Round #325 A Alena's Schedule
- CodeForces 325# A. Alena's Schedule
- coderforce 586A Alena's Schedule
- Code Forces 586 A. Alena's Schedule(水~)
- Marker's schedule , Manager's schedule
- Maker's Schedule, Manager's Schedule
- Today‘s schedule
- China's lunar work schedule
- How to schedule the thread's priority?
- ZOJ 3653 Sleeper's Schedule(DP)
- HDU 6180 Schedule(水题)
- Schedule
- schedule
- schedule
- ELK之ES2.4.1双实例平滑升级调优至5.2.1踩坑并supervisor管理记
- 2.3 Controlling Companies<DFS>
- LOD与DC-DC区别及应用
- Java中的final
- 【UE4】 第10讲 【MOBA制作日记】 Matinee相机过场动画
- Alena's Schedule[水题]
- Android Crash之Java Crash分析
- Eclipse 的 Debug 介绍与技巧
- leetcode350~Intersection of Two Arrays II
- Mac OS X下Maven的安装与配置
- 【Java】五种常见排序之----------------归并排序
- 浅析Hibernate VO与PO区别
- 取数字问题
- Python正则匹配中文与编码总结