codeforces586A Alena's Schedule(模拟)
来源:互联网 发布:淘宝浅草风是正品吗 编辑:程序博客网 时间:2024/06/05 09:54
题目链接
http://codeforces.com/problemset/problem/586/A
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.
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.
Print a single number — the number of pairs during which Alena stays at the university.
50 1 0 1 1
4
71 0 1 0 0 1 0
4
10
0
#include<stdio.h>#include<algorithm>#include<cstring>#include<iostream>using namespace std;int main(){ int n; int sum,ans,i,a[110],flag,k,j; flag=0; sum=0; memset(a,0,sizeof(a)); scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); if(flag==0&&a[i]==1) { flag=1; k=i; } } if(flag==0) printf("0\n"); else{ for(i=k;i<=n;i++) { if(a[i]==1) { sum++; if(a[i+1]==0&&a[i+2]==0) { for(j=i+1;j<=n;j++) { if(a[j]!=0) { i=j-1; break; } } } } else{ if(a[i+1]==0) { for(j=i+1;j<=n;j++) { if(a[j]!=0) { i=j-1; break; } } } else sum++; } } printf("%d\n",sum); }}
- codeforces586A Alena's Schedule(模拟)
- Alena's Schedule(模拟)
- A. 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
- HDU 6180 Schedule【优先队列+模拟】
- How to schedule the thread's priority?
- ZOJ 3653 Sleeper's Schedule(DP)
- Schedule
- schedule
- schedule
- 解决VMware8安装CentOS等系统时出现Fatal IO error 11(Resource temporarilt unavaliable) on Xshell:1问题
- Caffe 多爱Python一丢丢,Cifar-10
- Dlib库的安装配置
- Tomcat 性能优化(连接数、线程、JVM、dir)
- Android 红圈营销项目 —— 自定义柱形图和自定义折线图
- codeforces586A Alena's Schedule(模拟)
- python if __name__ == '__main__' 详解
- 5.36(Geometry:area of a regular polygon)
- 《统计学习方法》+最小二乘拟合多项式系数推导过程+P12推导勘误
- 二叉树前序遍历
- 仿写聊天气泡界面
- iOS UICollectionView 详解
- Android基础入门教程——8.2.1 Bitmap(位图)详解
- tomcat 性能优化