#Algo0102. Bad Hair Day S
Bad Hair Day S
题目描述
Some of Farmer John's cows are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads.
Each cow i has a specified height and is standing in a line of cows all facing east (to the right in our diagrams). Therefore, cow i can see the tops of the heads of cows in front of her (namely cows , , and so on), for as long as these cows are strictly shorter than cow .
Consider this example:
-
- -
- - -
- - -
- - - - -
- - - - - -
1 2 3 4 5 6
Cows facing right -->
Cow #1 can see the hairstyle of cows #2, 3, 4.
Cow #2 can see no cow's hairstyle.
Cow #3 can see the hairstyle of cow #4.
Cow #4 can see no cow's hairstyle.
Cow #5 can see the hairstyle of cow 6.
Cow #6 can see no cows at all!
Let denote the number of cows whose hairstyle is visible from cow ; please compute the sum of through . For this example, the desired is answer .
输入格式
Line 1: The number of cows, .
Lines 2..: Line contains a single integer that is the height of cow .
输出格式
Line 1: A single integer that is the sum of through .
6
10
3
7
4
12
2
5