zoukankan      html  css  js  c++  java
  • CF div2 325 A

    A. Alena's Schedule
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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
    Note

    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.

    题意很简单,直接枚举扫一遍就行了。。。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <queue>
     5 #include <vector>
     6 #include <stack>
     7 
     8 using namespace std;
     9 
    10 const int M = 10005;
    11 const int maxn = 5000000;
    12 typedef long long ll;
    13 
    14 vector<int>G[maxn];
    15 queue<int>Q;
    16 stack<int>st;
    17 
    18 
    19 int a[maxn];
    20 
    21 int main()
    22 {
    23 
    24     int n;
    25     int ans = 0;
    26     scanf("%d",&n);
    27     int t;
    28     for(int i=1;i<=n;i++){
    29         scanf("%d",&a[i]);
    30 
    31     }
    32     for(int i=1;i<=n;i++){
    33         if(a[i]==0){
    34             if(i==1) continue;
    35             else if(i==n) continue;
    36             else if(a[i-1]==1&&a[i+1]==1) a[i] = 1;
    37         }
    38     }
    39     for(int i=1;i<=n;i++){
    40         if(a[i]==1) ans++;
    41     }
    42     printf("%d
    ",ans);
    43 
    44     return 0;
    45 }
    View Code
  • 相关阅读:
    javascript工具--控制台详解(转自 阮一峰博客)
    javascript基础知识--函数定义
    javascript基础知识--什么是构造函数?什么是实例化对象?
    移动端开发,几个你可能不知道的CSS单位属性。
    HTML标签语义化,裸奔都那么帅
    THREE.JS开发《我的世界》(一)
    Webpack + ES6 最新环境搭建与配置
    canvas实现3D魔方
    Canvas实现3D效果-可旋转的立方体
    实现记忆中的经典游戏-扫雷
  • 原文地址:https://www.cnblogs.com/lmlyzxiao/p/4873358.html
Copyright © 2011-2022 走看看