A. Petya and Catacombs
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.

Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute i, he makes a note in his logbook with number ti:

  • If Petya has visited this room before, he writes down the minute he was in this room last time;
  • Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute i.

Initially, Petya was in one of the rooms at minute 0, he didn't write down number t0.

At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook?

Input

The first line contains a single integer n (1 ≤ n ≤ 2·105) — then number of notes in Petya's logbook.

The second line contains n non-negative integers t1, t2, ..., tn (0 ≤ ti < i) — notes in the logbook.

Output

In the only line print a single integer — the minimum possible number of rooms in Paris catacombs.

Examples
input
2
0 0
output
2
input
5
0 1 0 1 3
output
3
Note

In the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.

In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1.

题意:

地下墓穴有很多房间和房间之间的双向通道,探险家在里面探索房间。如果到了之前来过的房间,探险家会在记录一个数字t,t是他上次到这个房间记录的时间,如果这个房间他没来过他就会标记一个当前时间i小的t。通过这些他记录下来的时间t,让你求出最少房间的可能。

思路:

乍一看很复杂,但是题目线索给的很清晰了,一个房间记录的t有两种可能:1.上次来过t是上一次到达这个房间的时间。2.没来过这个房间,t是小于当前时间的一个数字,想让房间最少,当然是尽量选择第一种可能啊。

如果每次都是访问之前到达过的房间的话,是不会有相同的值出现的,一开始会在1个房间,此时时间为0s,如第一个样例: 0 0 ,第一个0代表0秒在的房间,设为房间1 ,第二个0,就不能代表0s在的房间了,因为0s是在1房间,但1房间上一次访问是1s时,1房间记录的应该是1。矛盾了,所以只能是第二种可能,未到过的房间,0是小于当前时间i的随机数。

实现代码:

#include<bits/stdc++.h>
using namespace std; int main()
{
int n,ans,i,a[],b[];
scanf("%d",&n);
ans = ;
memset(b,,sizeof(b));
for(i=;i<=n;i++)
scanf("%d",&a[i]);
for(i=;i<=n;i++){
if(!b[a[i]])
b[a[i]]=;
//cout<<a[i]<<endl;
else ans++;
}
cout<<ans<<endl;
}

codeforces 889A的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. Centos6.4安装配置sendmail

    一.安装sendmail yum install -y sendmail yum install -y sendmail-cf 二. 安装salauthd //使用SMTP认证,需要安装saslaut ...

  2. 计算机视觉-sift(2)代码理解

    之前结合不同人的资料理解了sift的原理,这里通过opencv中的代码来加深对sift的实现的理解. 使得能够从原理性理解到源码级的理解.不过该博文还是大量基于<赵春江, opencv2.4.9 ...

  3. Jquery属性练习

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  4. Pythoner使用的豆瓣pip源

    主要示例: sudo pip install -i http://pypi.douban.com/simple/  flask-script Flask的扩展: flask-script是一个可以在f ...

  5. Django:admin后台汉化问题

    1.设置admin站点中文显示,即汉化admin后台管理站点. 方法一:修改settings文件 LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' 更改为: LANG ...

  6. kettle学习笔记(五)——kettle输出步骤

    一.概述 数据库表: • 表输出 • 更新,删除,插入/更新 • 批量加载(mysql,oracle) • 数据同步 文件: • SQL 文件输出 • 文本文件输出 • XML 输出 • Excel ...

  7. 大数据入门第二十二天——spark(一)入门与安装

    一.概述 1.什么是spark 从官网http://spark.apache.org/可以得知: Apache Spark™ is a fast and general engine for larg ...

  8. 大数据入门第十六天——流式计算之storm详解(二)常用命令与wc实例

    一.常用命令 1.提交命令 提交任务命令格式:storm jar [jar路径] [拓扑包名.拓扑类名] [拓扑名称] torm jar examples/storm-starter/storm-st ...

  9. PostgreSQL索引页

    磨砺技术珠矶,践行数据之道,追求卓越价值   [作者 高健@博客园  luckyjackgao@gmail.com] 本页目的,是起到索引其他所有本人所写文档的作用: 分类一:PostgreSQL基础 ...

  10. [arc076F]Exhausted?[霍尔定理+线段树]

    题意 地上 \(1\) 到 \(m\) 个位置摆上椅子,有 \(n\) 个人要就座,每个人都有座位癖好:选择 \(\le L\) 或者 \(\ge R\) 的位置.问至少需要在两边添加多少个椅子能让所 ...