#P1677. [USACO18FEB] Hoofball B

    ID: 11417 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>模拟2018USACOO2优化排序深度优先搜索 DFS

[USACO18FEB] Hoofball B

Problem Description

To prepare for the upcoming hoofball tournament, Farmer John is training his NN cows (for convenience, numbered 1N1\ldots N, where 1N1001\le N\le 100) to pass balls. The cows are standing in a line along one side of the barn; cow ii is located at position xix_i away from the barn (1xi10001\le x_i\le 1000). Each cow is at a distinct position.

At the start of training, Farmer John will throw some number of balls to different cows. When cow ii receives a ball, whether from Farmer John or from another cow, she will pass the ball to the nearest cow (if there are multiple cows at the same distance from her, she will pass it to the one with the smaller xix_i). To ensure every cow gets a chance to practice passing, Farmer John wants to make sure that every cow holds a ball at least once. Help him compute the minimum number of balls he must throw at the beginning to achieve this goal. Assume that at the beginning he can throw balls to the best possible set of cows.

Input Format

The first line contains NN. The second line contains NN space-separated integers, where the ii-th integer is xix_i.

Output Format

Output the minimum number of balls Farmer John must throw at the beginning so that every cow holds a ball at least once.

5
7 1 3 11 4
2

Hint

In the sample above, Farmer John should throw balls to the cow at x=1x=1 and the cow at x=11x=11. The cow at x=1x=1 will pass her ball to the cow at x=3x=3, and after that this ball will be passed back and forth between the cow at x=3x=3 and the cow at x=4x=4. The cow at x=11x=11 will pass her ball to the cow at x=7x=7, then the ball will be passed to the cow at x=4x=4, and after that this ball will also be passed back and forth between the cow at x=3x=3 and the cow at x=4x=4. In this way, all cows will receive a ball at least once (either from Farmer John or from another cow).

It can be seen that there is no single cow such that, if Farmer John throws a ball to her, then eventually all cows will end up receiving a ball.

Translated by ChatGPT 5