Codeforce 886 Технокубок 2018 - Отборочный Раунд 3 C. Petya and Catacombs(结论题)

Posted zgqblogs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforce 886 Технокубок 2018 - Отборочный Раунд 3 C. 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, 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
Copy
2
0 0
output
Copy
2
input
Copy
5
0 1 0 1 3
output
Copy
3

思路
如果某个数k出现了 n 次,那么,在此过程中,探险家至少进入了n-1个房间,因为在这n次中,最多只会有一次,是回到之前的房间。
数字为0要特判,因为时间为0时在0位置


AC代码
#include<iostream>
#include<algorithm>
using namespace std;
int a[200086];
int num[200086];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        num[a[i]]++;
    }

    int ans=num[0];
    for(int i=1;i<n;i++){
        ans+=max(0,num[i]-1);
    }
    printf("%d
",ans);
}

  















以上是关于Codeforce 886 Технокубок 2018 - Отборочный Раунд 3 C. Petya and Catacombs(结论题)的主要内容,如果未能解决你的问题,请参考以下文章

Erlangе демо

php Возвращаетданныеометкахпостов,входящихвуказанную(ые)рубрику(и)

php Возвращаетданныеометкахпостов,входящихвуказанную(ые)рубрику(и)

javascript Корректнаявысотаокнаvhвмобильныхбраузерах

php Добавлениесогласиянаобработкуданныхвкомментариях

html Естькаталогоборудования。 УкаждогооборудованияестьдваTV - fileName,fileDownload.Унекоторыхпункт