#P7411. [USACO21FEB] Comfortable Cows S
[USACO21FEB] Comfortable Cows S
Description
Farmer Nhoj’s pasture can be viewed as a huge two-dimensional grid made of square cells (imagine a huge chessboard). Initially, the pasture is empty.
Farmer Nhoj will add cows () to the pasture one by one. The -th cow will occupy the cell , which is different from all cells already occupied by other cows ().
A cow is called “comfortable” if it has exactly three other cows adjacent to it horizontally or vertically. However, cows that are too comfortable often produce less milk, so Farmer Nhoj wants to add some extra cows until no cow (including the newly added cows) is comfortable. Note that the and coordinates of the added cows do not necessarily need to be within the range .
For each in , output the minimum number of cows Farmer Nhoj needs to add so that there are no comfortable cows, given that the pasture initially contains cows .
Input Format
The first line contains an integer . The next lines each contain two space-separated integers, giving the coordinates of a cow.
Output Format
Output lines. For each in , output one line containing the number of cows Farmer Nhoj needs to add.
9
0 1
1 0
1 1
1 2
2 1
2 2
3 1
3 2
4 1
0
0
0
1
0
0
1
2
4
Hint
For , Farmer Nhoj needs to add a cow at so that the cow at is no longer comfortable.
For , Farmer Nhoj’s best plan is to add cows at , , , and .
Problem by: Benjamin Qi.
Translated by ChatGPT 5
京公网安备 11011102002149号