A810 | Hoofball--Bronze
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
In preparation for the upcoming hoofball tournament, Farmer John is drilling
his $N$ cows (conveniently numbered $1\dots N$, where $1 \leq N \leq 100$) in
passing the ball. The cows are all standing along a very long line on one side
of the barn, with cow $i$ standing $x_i$ units away from the barn ($1 \leq x_i
\leq 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$ 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.
his $N$ cows (conveniently numbered $1\dots N$, where $1 \leq N \leq 100$) in
passing the ball. The cows are all standing along a very long line on one side
of the barn, with cow $i$ standing $x_i$ units away from the barn ($1 \leq x_i
\leq 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$ 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.
输入格式
The first line of input contains $N$. The second line contains $N$ space-
separated integers, where the $i$th integer is $x_i$.
separated integers, where the $i$th integer is $x_i$.
输出格式
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.
the cows, so that every cow can hold a ball at least once.
输入输出样例
输入 #1
5 7 1 3 11 4
输出 #1
2
In the above example, Farmer John should pass a ball to the cow at $x=1$ and
pass a ball to the cow at $x=11$. The cow at $x=1$ will pass her ball to the
cow at $x=3$, after which this ball will oscillate between the cow at $x=3$
and the cow at $x=4$. The cow at $x=11$ will pass her ball to the cow at
$x=7$, who will pass the ball to the cow at $x=4$, after which this ball will
also cycle between the cow at $x=3$ and the cow at $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.
pass a ball to the cow at $x=11$. The cow at $x=1$ will pass her ball to the
cow at $x=3$, after which this ball will oscillate between the cow at $x=3$
and the cow at $x=4$. The cow at $x=11$ will pass her ball to the cow at
$x=7$, who will pass the ball to the cow at $x=4$, after which this ball will
also cycle between the cow at $x=3$ and the cow at $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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted