A847 | Comfortable Cows--Silver
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Farmer Nhoj's pasture can be regarded as a large 2D grid of square "cells"
(picture a huge chessboard). Initially, the pasture is empty.
Farmer Nhoj will add $N$ ($1\le N\le 10^5$) cows to the pasture one by one.
The $i$th cow will occupy a cell $(x_i,y_i)$ that is distinct from the cells
occupied by all other cows ($0\le x_i,y_i\le 1000$).
A cow is said to be "comfortable" if it is horizontally or vertically adjacent
to exactly three other cows. Unfortunately, cows that are too comfortable tend
to lag in their milk production, so Farmer Nhoj wants to add additional cows
until no cow (including the ones that he adds) is comfortable. Note that the
added cows do not necessarily need to have $x$ and $y$ coordinates in the
range $0 \ldots 1000$.
For each $i$ in the range $1 \ldots N$, please output the minimum number of
cows Farmer Nhoj would need to add until no cows are comfortable if initially,
the pasture started with only cows $1\ldots i$.
(picture a huge chessboard). Initially, the pasture is empty.
Farmer Nhoj will add $N$ ($1\le N\le 10^5$) cows to the pasture one by one.
The $i$th cow will occupy a cell $(x_i,y_i)$ that is distinct from the cells
occupied by all other cows ($0\le x_i,y_i\le 1000$).
A cow is said to be "comfortable" if it is horizontally or vertically adjacent
to exactly three other cows. Unfortunately, cows that are too comfortable tend
to lag in their milk production, so Farmer Nhoj wants to add additional cows
until no cow (including the ones that he adds) is comfortable. Note that the
added cows do not necessarily need to have $x$ and $y$ coordinates in the
range $0 \ldots 1000$.
For each $i$ in the range $1 \ldots N$, please output the minimum number of
cows Farmer Nhoj would need to add until no cows are comfortable if initially,
the pasture started with only cows $1\ldots i$.
输入格式
The first line contains a single integer $N$. Each of the next $N$ lines
contains two space-separated integers, indicating the $(x,y)$ coordinates of a
cow's cell.
contains two space-separated integers, indicating the $(x,y)$ coordinates of a
cow's cell.
输出格式
The minimum number of cows Farmer Nhoj needs to add for each $i$ in $1 \ldots
N$, on $N$ separate lines.
N$, on $N$ separate lines.
输入输出样例
输入 #1
9 0 1 1 0 1 1 1 2 2 1 2 2 3 1 3 2 4 1
输出 #1
0 0 0 1 0 0 1 2 4
For $i=4$, Farmer Nhoj must add an additional cow at $(2,1)$ to make the cow
at $(1,1)$ uncomfortable.
For $i=9$, the best Farmer Nhoj can do is place additional cows at $(2,0)$,
$(3,0)$, $(2,-1)$, and $(2,3)$.
at $(1,1)$ uncomfortable.
For $i=9$, the best Farmer Nhoj can do is place additional cows at $(2,0)$,
$(3,0)$, $(2,-1)$, and $(2,3)$.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted