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<=2⋅105 ) — 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}<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 }
CF886C Petya and Catacombs