zoukankan      html  css  js  c++  java
  • C. Petya and Catacombs

    C. 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.

    题意:相同房间写下上一次到达的时间点,不同房间是随机一下,因为题目要最小答案 。

    分析:每个时间点只会出现一次,出现多次说明是随机的,也就是说出现多次的

    那些说明是不同房间,那么只要标记出现过的 然后统计再次出现的次数。0这个点也算

     1 #include <iostream>
     2 #include <algorithm>
     3 
     4 #define N 1000000
     5 using namespace std;
     6 int n;
     7 int k[N];
     8 int main(){
     9     cin>>n;
    10     for(int i=0;i<n;i++){
    11         cin>>k[i];
    12     }
    13     sort(k,k+n);
    14     int sum=1;
    15     for(int i=1;i<n;i++){
    16         if(k[i]==k[i-1])
    17             sum++;
    18     }
    19     cout<<sum<<endl;
    20     return 0;
    21 }
  • 相关阅读:
    WIN7每次从关闭屏幕状态恢复都会挂断宽带连接,请问如何解决?
    程序設計学习之路:不走弯路,就是捷径
    Customize Firefox "Close tab" button
    域名常识
    一到十的英文单词,一十二个月份的英文单词,四季的英文单词,第一,第二第三的英文单词
    Dependency Walker
    刪除當前目錄隱藏文件,非隱藏文件,文件夾等好用的批處理。
    使用 Sandcastle Help File Builder 制作 VS.NET 的 HELP 文件
    字符“23.00”转成int型!Input string was not in a correct format.
    VisualStudio 2010 SP1安装时提示计算机环境导致无法安装的解决办法
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/8010655.html
Copyright © 2011-2022 走看看