1536_Piggybanks

2022-5-16 18:17| 发布者: Hocassian| 查看: 49| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-2-89503897356000-Problem List-采集的数据-后羿采集器.html

Pro.ID

1536

Title

Piggy banks

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=1536

AC

15

Submit

24

Ratio

62.50%

时间&空间限制

  • Time Limit: 10000/5000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    Byteazar the Dragon has N piggy banks. Each piggy bank can either be opened with its corresponding key or smashed. Byteazar has put the keys in some of the piggy banks - he remembers which key has been placed in which piggy bank. Byteazar intends to buy a car and needs to gain access to all of the piggy banks. However, he wants to destroy as few of them as possible. Help Byteazar to determine how many piggy banks have to be smashed.


    Write a programme which:  

    • reads from the standard input the number of piggy banks and the deployment of their corresponding keys,  

    • finds the minimal number of piggy banks to be smashed in order to gain access to all of them,  

    • writes the outcome to the standard output.

    输入

    注意:输入包含多个测试数据。


    The first line of the standard input contains a single integer  N (1 ≤ N 1,000,000) - this is the number of piggy banks owned by the dragon. The piggy banks (as well as their corresponding keys) are numbered from 1 to N. Next, there are N lines: the i+1st line contains a single integer - the number of the piggy bank in which the ith key has been placed.

    输出

    Description

    Byteazar the Dragon has N piggy banks. Each piggy bank can either be opened with its corresponding key or smashed. Byteazar has put the keys in some of the piggy banks - he remembers which key has been placed in which piggy bank. Byteazar intends to buy a car and needs to gain access to all of the piggy banks. However, he wants to destroy as few of them as possible. Help Byteazar to determine how many piggy banks have to be smashed.


    Write a programme which:  

    • reads from the standard input the number of piggy banks and the deployment of their corresponding keys,  

    • finds the minimal number of piggy banks to be smashed in order to gain access to all of them,  

    • writes the outcome to the standard output.

    Input

    注意:输入包含多个测试数据。


    The first line of the standard input contains a single integer  N (1 ≤ N 1,000,000) - this is the number of piggy banks owned by the dragon. The piggy banks (as well as their corresponding keys) are numbered from 1 to N. Next, there are N lines: the i+1st line contains a single integer - the number of the piggy bank in which the ith key has been placed.

    Output

    The first and only line of the standard output should contain a single integer -- the minimal number of piggy banks to be smashed in order to gain access to all of the piggy banks.

    Sample Input
    4
    2
    1
    2
    4
    Sample Output
    2
    Hint
    In the foregoing example piggy banks 1 and 4 have to be smashed.
    Source

    样例输入

    4
    2
    1
    2
    4

    样例输出

    2

    提示

    In the foregoing example piggy banks 1 and 4 have to be smashed.


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部