CF886C Petya and Catacombs

题目描述

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 i i , he makes a note in his logbook with number ti t_{i} 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 i i .

Initially, Petya was in one of the rooms at minute 0 0 0 , he didn't write down number t0 t_{0} 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?

输入输出格式

输入格式:

 The first line contains a single integer n n n ( 1<=n<=2⋅105 1<=n<=2·10^{5} 1<=n<=2105 ) — then number of notes in Petya's logbook.

The second line contains n n n non-negative integers t1,t2,...,tn t_{1},t_{2},...,t_{n} t1,t2,...,tn ( $ 0<=t_{i}&lt;i $ ) — notes in the logbook.

 输出格式:

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

 题目翻译:

一位非常勇敢的探险家佩蒂娅曾经决定去探索巴黎的地下墓穴。由于佩蒂亚没有真正的经验,他的探索只是走过地下墓穴。              地下墓穴由几个房间和一些房间对之间的双向通道组成。有些通道可以把一个房间连接起来,由于通道是在不同的深度上建造的,所以它们之间不会相交。每一分钟,佩蒂娅都会任意地从他现在所在的房间中选择一条通道,然后在一分钟内到达通道另一端的房间。当他在第一分钟进入一个房间时,他会在日志中记下号码ti:              如果佩蒂亚以前去过这个房间,他会写下他上次在这个房间的时间;              否则,petya会严格地写下一个小于当前分钟i的任意非负整数。              起初,佩蒂亚在第0分钟的时候在其中一个房间里,他没有写下数字t0。              在他流浪期间的某个时候,佩蒂娅累了,扔掉了他的航海日志,回家了。瓦西亚找到了他的航海日志,现在他很好奇:根据佩蒂娅的航海日志,巴黎地下墓穴的最小房间数是多少? 

输入1:

2
0 0

输出1:

2

输入2:

5
0 1 0 1 3

输出2:

3

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cstdlib>
 6 using namespace std;
 7 const int maxn=2*1e5+10;
 8 int a[maxn];
 9 
10 int main(){
11     int n;
12     cin>>n;
13     memset(a,0,sizeof(a));
14     int x;
15     int ans=1;
16     while(n--){
17         cin>>x;
18         if(!a[x]){
19             a[x]=1;
20         }
21         else{
22             ans++;
23         }
24     }
25     cout<<ans<<endl;
26     return 0;
27 }

猜你喜欢

转载自www.cnblogs.com/Bravewtz/p/10354492.html
今日推荐