zoukankan      html  css  js  c++  java
  • codeforces 889A

    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[200020],b[200020];
        scanf("%d",&n);
        ans = 1;
        memset(b,0,sizeof(b));
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for(i=1;i<=n;i++){
            if(!b[a[i]])
              b[a[i]]=1;
                //cout<<a[i]<<endl;
           else ans++;
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    hdu 1551 恶心的卡精度题
    ubuntu下升级firefox
    清理windows垃圾
    hdu 1575 矩阵快速幂
    右键菜单中添加用记事本打开(转)
    hdu 1525 博弈
    PHP字符串函数(转)
    笔试注意事项
    .NET 2.0面向对象编程揭秘 继承
    李开复:21世纪7种人才最抢手
  • 原文地址:https://www.cnblogs.com/kls123/p/7875922.html
Copyright © 2011-2022 走看看