操作系统寒武纪 - 会让企业IT高兴吗?
629
2022-09-06
usaco2018 feb cu Hoofball
In preparation for the upcoming hoofball tournament, Farmer John is drilling his N
N cows (conveniently numbered 1…N
1…N , where 1≤N≤100
1≤N≤100 ) in passing the ball. The cows are all standing along a very long line on one side of the barn, with cow i
i standing xi
xi units away from the barn (1≤xi≤1000
1≤xi≤1000 ). Each cow is standing at a distinct location.At the beginning of the drill, Farmer John will pass several balls to different cows. When cow i
i receives a ball, either from Farmer John or from another cow, she will pass the ball to the cow nearest her (and if multiple cows are the same distance from her, she will pass the ball to the cow farthest to the left among these). So that all cows get at least a little bit of practice passing, Farmer John wants to make sure that every cow will hold a ball at least once. Help him figure out the minimum number of balls he needs to distribute initially to ensure this can happen, assuming he hands the balls to an appropriate initial set of cows.
INPUT FORMAT (file hoofball.in):
The first line of input contains N
N . The second line contains N
N space-separated integers, where the i
i th integer is xi
xi .
OUTPUT FORMAT (file hoofball.out):
Please output the minimum number of balls Farmer John must initially pass to the cows, so that every cow can hold a ball at least once.
SAMPLE INPUT:
5 7 1 3 11 4 SAMPLE OUTPUT:
2 In the above example, Farmer John should pass a ball to the cow at x=1
x=1 and pass a ball to the cow at x=11
x=11 . The cow at x=1
x=1 will pass her ball to the cow at x=3
x=3 , after which this ball will oscillate between the cow at x=3
x=3 and the cow at x=4
x=4 . The cow at x=11
x=11 will pass her ball to the cow at x=7
x=7 , who will pass the ball to the cow at x=4
x=4 , after which this ball will also cycle between the cow at x=3
x=3 and the cow at x=4
x=4 . In this way, all cows will be passed a ball at least once (possibly by Farmer John, possibly by another cow).
It can be seen that there is no single cow to whom Farmer John could initially pass a ball so that every cow would eventually be passed a ball.
Problem credits: Dhruv Rohatgi
每次传球都是往最近的地方传球 中文题意出问题了.. 如果相同距离 则向最左边传球
那么首先一遍dfs判断哪些只有一个入度 那么给他一个球 然后再dfs一下 看一下环的情况 给每个环一个 球 即可
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~