A900 | Balanced Photo--Gold
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Farmer John is arranging his $N$ cows in a line to take a photo ($1 \leq N
\leq 100,000$). The height of the $i$th cow in sequence is $h_i$, and the
heights of all cows are distinct.
As with all photographs of his cows, FJ wants this one to come out looking as
nice as possible. He decides that cow $i$ looks "unbalanced" if $L_i$ and
$R_i$ differ by more than factor of 2, where $L_i$ and $R_i$ are the number of
cows taller than $i$ on her left and right, respectively. That is, $i$ is
unbalanced if the larger of $L_i$ and $R_i$ is strictly more than twice the
smaller of these two numbers. FJ is hoping that not too many of his cows are
unbalanced.
Please help FJ compute the total number of unbalanced cows.
\leq 100,000$). The height of the $i$th cow in sequence is $h_i$, and the
heights of all cows are distinct.
As with all photographs of his cows, FJ wants this one to come out looking as
nice as possible. He decides that cow $i$ looks "unbalanced" if $L_i$ and
$R_i$ differ by more than factor of 2, where $L_i$ and $R_i$ are the number of
cows taller than $i$ on her left and right, respectively. That is, $i$ is
unbalanced if the larger of $L_i$ and $R_i$ is strictly more than twice the
smaller of these two numbers. FJ is hoping that not too many of his cows are
unbalanced.
Please help FJ compute the total number of unbalanced cows.
输入格式
The first line of input contains $N$. The next $N$ lines contain $h_1 \ldots
h_N$, each a nonnegative integer at most 1,000,000,000.
h_N$, each a nonnegative integer at most 1,000,000,000.
输出格式
Please output a count of the number of cows that are unbalanced.
输入输出样例
输入 #1
7 34 6 23 0 5 99 2
输出 #1
3
In this example, the cows of heights 34, 5, and 2 are unbalanced.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted