CodeForces 325# A. Alena's Schedule

本文介绍了一个关于大学生课程安排的问题,通过算法找到最优的学习路径,确保学生可以在最少的时间浪费下完成学业。具体而言,该算法会根据课程表来确定学生实际需要留在学校上课的时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击就送屠龙宝刀

A. Alena’s Schedule

time limit per test
 1 second

standard output
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 test(s)
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

题目大意:寻找开头的0还有类似101这种中间有1个0的玩意儿把0改成1然后for一边统计1的数目输出。。

#include<iostream>
#include<cstdio>

using namespace std;
bool nu[2000];
bool nn[2000];

int main()
{
    int n,ans=0;
    scanf("%d",&n);

    for(int i=1;i<=n;i++)
    {
        scanf("%d",&nu[i]);
    }

    for(int i=1;i<=n;i++) nn[i]=nu[i];

    for(int i=2;i<n;i++)
    {
        if(nu[i]==0&&nu[i-1]==1&&nu[i+1]==1) nn[i]=1;
    }

    for(int i=1;i<=n;i++)
    {
        if(nn[i]==1) ans++;
    }

    cout<<ans;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值