zoukankan      html  css  js  c++  java
  • A. Detective Book

    A. Detective Book

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The ii-th page contains some mystery that will be explained on page aiai (aiiai≥i).

    Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page ii such that Ivan already has read it, but hasn't read page aiai). After that, he closes the book and continues to read it on the following day from the next page.

    How many days will it take to read the whole book?

    Input

    The first line contains single integer nn (1n1041≤n≤104) — the number of pages in the book.

    The second line contains nn integers a1,a2,,ana1,a2,…,an (iaini≤ai≤n), where aiai is the number of page which contains the explanation of the mystery on page ii.

    Output

    Print one integer — the number of days it will take to read the whole book.

    Example

    input

    9
    1 3 3 6 7 6 8 8 9
    

    output

    4

    Note

    Explanation of the example test:

    During the first day Ivan will read only the first page. During the second day Ivan will read pages number 2 and 3. During the third day — pages 4-8. During the fourth (and the last) day Ivan will read remaining page number 9.

    题意:lvan看一本页数为n页的书,求出他要多少天看完(如果当前的所有谜团没有解决的话,lvan就会一直看下去)。

    题解:找出当前所看到的最大页数,如果最大页数正好等于当前看到的页数,那就天数就加1。

    #include<iostream>
    #include<cstdio>
    #include<memory.h>
    
    using namespace std;
    
    int main()
    {
        int n,x,maxx=-1,ans=0;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>x;
            if(maxx<x)        //找出当前看到的最大页数
                maxx=x;
            if(maxx==i)        //判断最大页数是不是当前页数
                ans++;
        }
        cout<<ans<<endl;
        return 0;
    }


  • 相关阅读:
    CF938E Max History
    经典论文系列 | 目标检测--CornerNet & 又名 anchor boxes的缺陷
    在 Intenseye,为什么我们选择 Linkerd2 作为 Service Mesh 工具(Part.2)
    在 Intenseye,为什么我们选择 Linkerd2 作为 Service Mesh 工具(Part.1)
    Java概述
    算法 --- 二分法 冒泡排序 递归 快速排序
    二维数组
    数组
    SNMP "Simple Network Management Protocol" "简单网络管理协议"。
    常用api --- BigDecimal 包装类 Integer Arrays
  • 原文地址:https://www.cnblogs.com/buhuiflydepig/p/10639172.html
Copyright © 2011-2022 走看看