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 (ai≥iai≥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 (1≤n≤1041≤n≤104) — the number of pages in the book.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (i≤ai≤ni≤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=-,ans=;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>x;
if(maxx<x) //找出当前看到的最大页数
maxx=x;
if(maxx==i) //判断最大页数是不是当前页数
ans++;
}
cout<<ans<<endl;
return ;
}

A. Detective Book的更多相关文章

  1. [原]一个针对LVS的压力测试报告

    LVS 测试报告 测试计划 基本功能测试 流量压力测试 响应时间测试 配置正确性测试 灾难恢复测试 测试点 基本功能测试 客户端IP地址正确性 RealServer 访问Internet测试(包括Ip ...

  2. Lesson 15 Good news

    Text The secretary told me that Mr. Harmsworth would see me. I felt very nervous when I went into hi ...

  3. Lesson 7 Too late

    Text The plane was late and detectives were waiting at the airport all morning. They were expecting ...

  4. oc集合

    本人之前学习过一年半ios开发 由于行情太过凄惨,故转前端.心在前端,苹果亦难忘!把我平时的笔记作出给大家总结! 回顾之前的知识 便利初始化函数:框架类库中的一些类有一系列的以init开头的方法,这些 ...

  5. words

    conscious[英][ˈkɒnʃəs][美][ˈkɑnʃəs]consensus[英][kənˈsensəs][美][kənˈsɛnsəs] scious sensuswaterflood; de ...

  6. [DFNews] Cellebrite UFED系列更新, 支持IOS7

    10月15日,Cellebrite公司对旗下产品进行了更新,包括UFED Classic.UFED Touch.Physical Analyzer.Logical Analyzer.Phone Det ...

  7. 【英语魔法俱乐部——读书笔记】 2 中级句型-复句&合句(Complex Sentences、Compound Sentences)

    [英语魔法俱乐部——读书笔记] 2 中级句型-复句&合句(Complex Sentences.Compound Sentences):(2.1)名词从句.(2.2)副词从句.(2.3)关系从句 ...

  8. 【英语魔法俱乐部——读书笔记】 1 初级句型-简单句(Simple Sentences)

    第一部分 1 初级句型-简单句(Simple Sentences):(1.1)基本句型&补语.(1.2)名词短语&冠词.(1.3)动词时态.(1.4)不定式短语.(1.5)动名词.(1 ...

  9. iOS.ReactNative-5-make-react-native-to-support-dynamically-update

    基于React Native来实现App的热更新 热更新: 类似Hot-Patching,在程序不发布版本的前提下,对部分功能或者全部功能进行修改或者升级. JSX 1. JSX简介 1.1 http ...

随机推荐

  1. Luogu P3810 【模板】三维偏序(陌上花开)(CDQ分治)

    题目 以三维偏序为例来讲一下CDQ分治. CDQ的本质就是把一个序列分成两段,计算左边对右边的贡献,然后分治. 不过一般都是先分治到底再从下往上算,这样可以先归并再算. 比如这道题,我们先按第一维排序 ...

  2. HDU 6662 Acesrc and Travel 换根DP,宇宙最傻记录

    #include<bits/stdc++.h> typedef long long ll; using namespace std; const int maxn=1e6+50; cons ...

  3. predis操作redis方法大全

    //连接redis $redis = new Redis(); $redis->connect("127.0.0.1", 6379); //普通set/get操作 $redi ...

  4. postgres 常规操作杂记

    分布式:1.扩容不方便(数据重分布)2.分布键变更很麻烦3.分布键选择(架构设计)谨慎4.跨库join性能差5.分布式事务性能差6.sql限制多,功能确实多7.应用改造成本巨大8.全局一致性时间点恢复 ...

  5. 刚接触SkyLine的一点小收获与感触

    因为刚接触Skyline不到一个星期,也怕把学习到的忘记掉,所以写一点学习到的一些皮毛的东西,赶紧记录一下,怕回头忘记 1.网上关于web端的开发非常多,也有很多牛人分享自己的经验,所以学习起来也相对 ...

  6. RabbitMQ核心技术总结

    RabbitMQ和kafka类似,也是一个消息服务.RabbitMQ是轻量级的,易于部署在内部和云端.RabbitMQ支持多种消息协议,可以部署在分布式集群中,能够满足高规模,高可用性要求.Rabbi ...

  7. 从Spring看Web项目开发

    之前简单介绍过Spring框架,本文换个角度重新诠释Spring.使用Java语言开发的项目,几乎都绕不过Spring,那么Spring到底是啥,为何被如此广泛的应用,下面从以下两个问题出发来剖析Sp ...

  8. python 写入JSON中文乱码解决方法

    在将一个字典添加入json中时多加入一个参数就可以了 json.dumps(dict(item), ensure_ascii=False) 例子 with open('zh-cn.json','w', ...

  9. 21、Nginx 常见问题

    1.多个server_name容易产生冲突,会按照如下顺序匹配 1.首先选择所有的字符串完全匹配的server_name.(完全匹配) 2.选择通配符在前面的server_name,如*.bgx.co ...

  10. shell 获取结果中的第n列,第n行

    ls -l | awk '{print $5}' | sed -n '2p' awk 是很实用的文本处理命令,print 到后带的是你要获取第几列,sed -n 是指定第几行.