文档章节

CodeForces 325# A. Alena's Schedule

机智的帝江
 机智的帝江
发布于 2016/10/30 09:59
字数 530
阅读 5
收藏 0

点击就送屠龙宝刀

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

本文转载自:http://blog.csdn.net/loi__dijiang/article/details/49096119

机智的帝江
粉丝 0
博文 89
码字总数 4734
作品 0
莱芜
程序员
私信 提问
Codeforces 1082B Vova and Trophies 模拟,水题,坑 B

Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn trophies in different competitions. Each trophy is either golden or silver......

Kidgzz
2018/12/04
0
0
Codeforces积分系统介绍

一、艾洛积分系统(Elo Ranking System) 请参考 https://blog.csdn.net/haishu_zheng/article/details/80480284 二、Codeforces积分系统 类似于艾洛积分系统,但是具体算法没公布。 详情请参考...

海天一树X
2018/05/28
0
0
CodeForces 797C

一开始,给你一个字符串s;两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加到t后面; 2.将t的最后一个字符加到u的后面去 要求最后使得s和t字符串变成空串; 并且得到的u的字符串的字典序...

阿豪boy
2017/08/16
2
0
Codeforces Round #588 (Div. 2)-E. Kamil and Making a Stream-求树上同一直径上两两节点之间gcd的和

Codeforces Round #588 (Div. 2)-E. Kamil and Making a Stream-求树上同一直径上两两节点之间gcd的和 【Problem Description】 给你一棵树,树上每个节点都有一个权值。定义(1sim v)的最短路...

__Simon
09/27
0
0
Codeforces Round #500 (Div. 2) BC

CodeForces 1013B And CodeForces 1013C Photo of The Sky B 可以发现只有一次与操作是有意义的,所以答案只有-1,0,1,2四种情况 2 #define show(a) cout << #a << " = " << a << endl; 3 ......

cjc7373
2018/07/30
0
0

没有更多内容

加载失败,请刷新页面

加载更多

ArrayList输出的几种方法

ArrayList输出的几种方法!!! import java.util.ArrayList;import java.util.Iterator;import java.util.List; public class ArrayList1 {    public static void main(Str......

柒礼拜
21分钟前
5
0
ZKEYS公有云管理系统账号注册流程

1.进入ZKEYS官网,单击首页右上角免费注册按钮 2.选择注册方式,有手机注册和有限注册两种 3.填写手机或邮箱,设置密码 4.注册完成,即可登录ZKEYS会员中心 单击右上角免费注册按钮 填写手机...

BirdCloud
23分钟前
4
0
好程序员web前端分享web前端入门知识

好程序员web前端分享web前端入门知识,给大家分享一些Web前端工程师要掌握的基础知识和技能,下面一起来看看。 1、网页的基本结构(HTML、CSS) HTML是一种标记语言,而不是编程语言,最基本是...

好程序员官网
25分钟前
5
0
使用pyinstaller打包qt程序提示 找不到.dll问题

使用pyinstaller打包qt程序,运行时提示 找不到.dll问题。 import osimport sysif hasattr(sys, 'frozen'): os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH'] 需要在......

開援带碼
27分钟前
4
0
mysql导入数据库

原链接:https://msd.misuland.com/pd/3223833238703185046 发现row size长度过长,导致出现错误: 解决方案: 查询系统参数: show variables like '%innodb_strict_mode%';show variab......

tobej
29分钟前
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部