22539_StackingTower

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

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

Pro.ID

22539

Title

Stacking Tower

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1200/400 MS (Java/Others)     Memory Limit: 131072/65536 K (Java/Others)
  • 描述

    One of the most common children’s toys is a stacking tower, which consists of a series of rings of different sizes and a tapered rod which can hold the rings. The rings and rod are designed so that when the rings are placed in descending order by size, they fit exactly on the rod. Further, each ring, if placed by itself on the rod will go no lower than its position when all rings are on the rod. The diagram on the left shows an example of this toy which uses five rings, numbered 1 (smallest) to 5 (largest)

    Unless endowed with super-genius mental faculties, most infants will place the rings in a random order on the rod, which results in some rings sticking over the top of the rod. The above diagram on the right shows the result of one such random placement. Your job will be to determine the number of rings which sit above the rod given a random ordering of the rings. You may assume that the rings may be stacked arbitrarily high without falling over.

    输入

    Input will consist of multiple problem instances. Each instance consists of a single line of the form  n  r1  r2  ...  rn . The positive integer n specifies the number of rings ( <= 100 ), and the remaining n integers give the order the rings are put on the rod.

    A value of n = 0 will terminate input.

    输出

    Description

    One of the most common children’s toys is a stacking tower, which consists of a series of rings of different sizes and a tapered rod which can hold the rings. The rings and rod are designed so that when the rings are placed in descending order by size, they fit exactly on the rod. Further, each ring, if placed by itself on the rod will go no lower than its position when all rings are on the rod. The diagram on the left shows an example of this toy which uses five rings, numbered 1 (smallest) to 5 (largest)

    Unless endowed with super-genius mental faculties, most infants will place the rings in a random order on the rod, which results in some rings sticking over the top of the rod. The above diagram on the right shows the result of one such random placement. Your job will be to determine the number of rings which sit above the rod given a random ordering of the rings. You may assume that the rings may be stacked arbitrarily high without falling over.

    Input

    Input will consist of multiple problem instances. Each instance consists of a single line of the form  n  r1  r2  ...  rn . The positive integer n specifies the number of rings ( <= 100 ), and the remaining n integers give the order the rings are put on the rod.

    A value of n = 0 will terminate input.

    Output
    For each problem instance, you should output one line containing an integer indicating the number of rings sticking over the top of the rod.
    Sample Input
    5 5 4 3 2 1
    5 4 5 1 3 2
    8 1 2 3 4 5 6 7 8
    20 11 10 19 7 12 14 5 2 3 1 8 6 13 17 18 9 4 20 15 16
    0
    Sample Output
    0
    2
    7
    11
    Source

    样例输入

    5 5 4 3 2 1
    5 4 5 1 3 2
    8 1 2 3 4 5 6 7 8
    20 11 10 19 7 12 14 5 2 3 1 8 6 13 17 18 9 4 20 15 16
    0

    样例输出

    0
    2
    7
    11

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部