CodeForces 890C Petya and Catacombs

来源:互联网 发布:阿里云客服一天多少钱 编辑:程序博客网 时间:2024/06/10 17:51

Description

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 minutei, he makes a note in his logbook with numberti:

  • 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 minutei.

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

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 integerst1, 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.

Example
Input
20 0
Output
2
Input
50 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.

题目大意:

一个人去山洞里探险, 他有个小本本去记录他每次走过的山洞的情况。 起初第0秒时他站在第一个山洞。记录的根据是: 1.如果他来过这个山洞, 那么他记录的数字就是上一次他来到这个山洞的时间数 2.如果他没走过这个山洞就随便记录一个比之前写过的值小的数字。现在又有一个探险家来到这个山洞并且拿到了这个本本, 请问这个探险家最少能知道一共有几个山洞。

解题思路:

根据题目所给题意, 我们既然要求最小山洞数, 就要贪心的认为只要是符合条件一的数字我们都认为是去到了去过的山洞, 特判+贪心 一遍过。

举个例子:

        0      1     0      1      3(本号)

1 -> 1 -> 1 -> 2 -> 3 -> 2   (洞号)

0      1     2      3      4     5 (时间)

代码:

#include <iostream>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <cmath>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>

using namespace std;

/*
 *ios::sync_with_stdio(false);
 */

typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x7fffffff;
const int mod = 1000000;
const int Max = (int) 2e5 + 9;

struct node {
    int num;
    bool vis;
}arr[Max];

int main() {
    int n, ans = 1;
    scanf("%d", &n);
    // initialization
    memset(arr, 0, sizeof(arr));

    for (int i = 1; i <= n; ++i) {
        scanf("%d", &arr[i].num);
    }
    arr[0].num = 0;
    for (int i = 1; i <= n; ++i) {
        // come again
        if ((arr[i].num == i - 1) && !arr[i - 1].vis) {
            arr[i - 1].vis = 1;
            arr[i].num = i;
            continue ;
        } else if (arr[arr[i].num].vis == 0) {
            arr[arr[i].num].vis = 1;
            arr[i].num = i;
            continue ;
        // not come
        } else {
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}



原创粉丝点击