A. Detective Book
A. Detective Book
2 seconds
256 megabytes
standard input
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的更多相关文章
- [原]一个针对LVS的压力测试报告
LVS 测试报告 测试计划 基本功能测试 流量压力测试 响应时间测试 配置正确性测试 灾难恢复测试 测试点 基本功能测试 客户端IP地址正确性 RealServer 访问Internet测试(包括Ip ...
- Lesson 15 Good news
Text The secretary told me that Mr. Harmsworth would see me. I felt very nervous when I went into hi ...
- Lesson 7 Too late
Text The plane was late and detectives were waiting at the airport all morning. They were expecting ...
- oc集合
本人之前学习过一年半ios开发 由于行情太过凄惨,故转前端.心在前端,苹果亦难忘!把我平时的笔记作出给大家总结! 回顾之前的知识 便利初始化函数:框架类库中的一些类有一系列的以init开头的方法,这些 ...
- words
conscious[英][ˈkɒnʃəs][美][ˈkɑnʃəs]consensus[英][kənˈsensəs][美][kənˈsɛnsəs] scious sensuswaterflood; de ...
- [DFNews] Cellebrite UFED系列更新, 支持IOS7
10月15日,Cellebrite公司对旗下产品进行了更新,包括UFED Classic.UFED Touch.Physical Analyzer.Logical Analyzer.Phone Det ...
- 【英语魔法俱乐部——读书笔记】 2 中级句型-复句&合句(Complex Sentences、Compound Sentences)
[英语魔法俱乐部——读书笔记] 2 中级句型-复句&合句(Complex Sentences.Compound Sentences):(2.1)名词从句.(2.2)副词从句.(2.3)关系从句 ...
- 【英语魔法俱乐部——读书笔记】 1 初级句型-简单句(Simple Sentences)
第一部分 1 初级句型-简单句(Simple Sentences):(1.1)基本句型&补语.(1.2)名词短语&冠词.(1.3)动词时态.(1.4)不定式短语.(1.5)动名词.(1 ...
- iOS.ReactNative-5-make-react-native-to-support-dynamically-update
基于React Native来实现App的热更新 热更新: 类似Hot-Patching,在程序不发布版本的前提下,对部分功能或者全部功能进行修改或者升级. JSX 1. JSX简介 1.1 http ...
随机推荐
- 【洛谷P1816】忠诚——ST表做法
看了两个小时RMQ并位运算,对二进制勉勉强强有了个初步了解,不能说精通(可能今年CSP前都做不到精通),但是记熟板子做做题还是没有问题的 以下是正式题解,相信你看过了题目,我介绍的是ST表的做法(很简 ...
- (电脑重置之后)win10在桌面点右键鼠标一直转圈;无法点击桌面图标;
昨天重置系统之后,发现了这个毛病.桌面任务栏都能正常点击,就是一到桌面,无法点击桌面上面的图标(刚开机的时候还可以点).想新建文件夹来着,一点右键,鼠标即开始转圈圈.本来以为自己能好,结果第二天了还这 ...
- 2019中山纪念中学夏令营-Day19 数论初步【GCD(最大公约数),素数相关】
关于GCD的一些定理或运用的学习: 1. 2.二进制算法求GCD 思想:使得最后的GCD没有2(提前把2提出来) 代码实现: #include <cstdio> #define int l ...
- python-day30(正式学习)
单例模式 什么是单例模式 单例模式:基于某种方法实例化多次得到实例是同一个 为什么用单例模式 当实例化多次得到的对象中存放的属性都一样的情况,应该将多个对象指向同一个内存,即同一个实例 用类方法来实现 ...
- js小数和百分数的转换
一.百分数转化为小数 function toPoint(percent){ var str=percent.replace("%",""); str= str/ ...
- django自带登录认证与登录自动跳转
# 导入django自带模块 from django.contrib.auth import authenticate, login, logout # 使用authenticate进行认证,使用lo ...
- sql server len函数
len函数 --返回字符表达式中的字符数 --如果字符串中包含前导空格和尾随空格,则函数将它们包含在内 --LEN对相同的单字节和双字节字符串返回相同的值 --示例:select LEN('no'), ...
- QuickSort(快排)的JAVA实现
QuickSort的JAVA实现 这是一篇算法课程的复习笔记 用JAVA对快排又实现了一遍. 先实现的是那个easy版的,每次选的排序轴都是数组的最后一个: package com.algorithm ...
- js 格式化 json 字符串
1.JSON.stringify的三个参数 var json = {"@odata.context":"$metadata#AddTableOne_466281s&quo ...
- less 经典范例 bootstrap 的 less 版本 常用 less 代码
1. bootstrap 的 less 版本 2.less 文件分布 /*! * Bootstrap v3.3.7 (http://getbootstrap.com) * Copyright 2011 ...