Previous questions ant cold time limit: 1.0s memory limit: 256.0MBProblem description There are n ants on the slender straight pole with a length of 100 centimeters. They have their heads on the left, some facing to the right.
Each ant can only climb along the pole, at a speed of 1 centimeters per second.
When two ants meet, they will turn around at the same time and crawl in the opposite direction.
Of these ants, 1 ants have a cold. And when they meet with other ants, they will infect the ant with the cold.
Please calculate how many ants have a cold when all the ants are climbing away from the pole. Input format the first line enters an integer n (1 < n < 50), which represents the total number of ants.
The next line is n a space-separated integer XI ( -100 < Xi <), the absolute value of Xi, indicating the distance the ant leaves the left end of the pole. A positive value indicates a head to the right, a negative value indicates a head to the left, no 0 values appear in the data, and no two ants occupy the same position. Among them, the first data represents the ants catching a cold. The output format requires an output of 1 integers, indicating the number of last cold ants. Sample Input 3
5-2 8 Example Output 1 sample input 5
-10 8-20 12 25 Sample Output 3
Blue Bridge Cup this XX practice system, all day 502 Bad Gateway, really no words dead, yesterday on a day 502 bad Gateway
Idea: Because the ants will meet each other, and each encounter can be seen as a "pass", so as long as the number of ants to find out with the cold ants can be, and when there is more than one ant and cold ants opposite the line, the cold ants will be towards the other side of the infection, And as long as the statistics in another direction and now the number of cold ants opposite the total can be, the sum is the answer
AC Code:
Blue Bridge cup-ants cold