Blue Bridge cup-ants cold

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.