The city of Oneway has a 3 × 5 park, and a 5 1 3 × 1 0 2 5 grassland that they own.
To make it easier to run search and rescue, they want to fill several grid squares with huge trees that prevent passage, so that in the remaining area there is exactly one path between any two grid squares that does not revisit any cells. (We only allow for moving between squares that share a side, and not squares that share a corner.)
For the 3 × 5 park, several proposals were submitted, of which 2 are displayed:
The proposal on the left was immediately rejected because there were two ways to go between A and B, and no ways to go between A and C. The proposal on the right was accepted, as it fulfilled their conditions.
The town is under some economic hardship, so they will award the contract to the construction company that uses the fewest trees. For the park, they eventually awarded the contract to another proposal that only used 3 squares of trees.
The 5 1 3 × 1 0 2 5 grassland represents a huge contract that your company wants to be awarded. Determine the minimum number of squares of trees that are needed to fulfill the desires of the town, and allow your company to come out on top.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
View my comment which shows that the important aspects of the problem are
1. We have a connected tree, which gives us a relationship between the number of vertices and edges that are left.
2. The (almost) equality condition which tells us that each removed vertex (except 1) has to remove exactly 4 edges.
This solution uses a "structure avoider and finder" approach. As the structure avoider, we list out the conditions that has to be satisfied, like saying that each removed vertex connects to 4 edges, which implies that at the optimal scenario, no two trees share an edge (since the second tree would then remove 3 edges only). Furthermore, there is exactly 1 tree on the side by not the corner (corresponding to the vertex that removes 3 edges only).
As the structure finder, we now have a lot of information to start to find a possible configuration. For example, the resultant (slightly) checkerboard placement is due to the need for 1 connected component while the trees are on disconnected squares.
Sometimes, we are not able to construct the example. If so, we should take up the role of the structure avoider again, and see what other conditions we can introduce. This back-and-forth approach allows us to narrow down our search space as we try to determine what the answer is.
The first half of the solution could be simplified considerably, using the ideas that you've already expressed
2 v c − c − v − ( 4 n − 1 ) ≤ number of edges = v c − n − 1
Simplifying this, we obtain ( v − 1 ) ( c − 1 ) + 1 ≤ 3 n .
Log in to reply
That works. Either way, the idea for the lower bound is to look at the segments of the grid and count them up.
I can't figure out why my more clumsy solution of 174762 is wrong. I can draw a path round the whole park and two paths going EW and NS through the centre. I'll need two trees at the end to ensure the one-path rule but bear with me for now.
The paths within each segment behave like a series of fractals. Odd rows need (m-1)/2 trees. Multiples of 2, but not 4, require (m-1)/4. This continues and for the big park this gives:
256x512 + 128x256 + 64x128 + ...2x4.
This is 2^17+ 2^15+ 2^13+ 2^11+... +2^5+ 2^3 =(2^2+1)×(2^4+1)×(2^8+1)×2^3 =174760
Add two trees in centre of each path running along the north and south side and we cut all alternative routes.
Log in to reply
I've realised my simple approach requires a square park. It would get the right answer if I halved the solution for 1025 x 1025.
Log in to reply
Oh, that's really interesting! Can you write up your version of the problem and post that solution?
I love seeing such construction problems, and getting insight into how the restrictions influence the outcome.
While I didn't get a clear idea of the description, I suspect your construction gives us half of Ivan's. IE truncate columns after the tree at the bottom row.
Log in to reply
@Calvin Lin – It's nowhere near as elegant and works in special cases where the shape is 2^n+1 by 2^n+1. Take a 5x5 grid (n=2) and add 2^2 trees in positions with even x,y coordinates creates a simple path. 2 more trees are need to make this unique.
It then proceeds by induction if we add new rows and columns between each existing row and column. This 9x9 grid still has those 6 trees but needs another 4 trees in each even row (4×4). Add another 8 rows and columns between these requires another 8x8 trees.
For the larger grid of 2^n+1 squared, we can achieve the task with 2^(n-2)+2^(n-4)+...2^4+2^2+2.
And for the given problem it is simply half the solution for 1025x1025.
Log in to reply
@Malcolm Rich – I believe that the constructions are going to work for special cases. E.g. Ivan's works for ( 2 n + 1 ) × ( 2 n + 1 + 1 ) .
I think that the general case is going to be hard to figure out. We have a bound, but I doubt it is tight in "non-trivially many" cases.
Log in to reply
@Calvin Lin – I'm more optimistic that it is a solution but I see why we haven't proved it here.
@Calvin Lin – Can we think of a solution for 4x6 that achieves the goal with the stated limit, or 6 trees. I can only find solutions with 7 trees which suggests that the minimum isn't a solution in all cases.
Log in to reply
Log in to reply
@Calvin Lin – I am struggling to find a solution to a 6x6 that uses fewer than 10. If anyone can find the solution I would be interested in seeing it.
Log in to reply
@Abel McElroy – I think the minimum is indeed 10. Using the same perimeter bound, if there are a , b , c trees in the corners, sides, and interior of the park, we need 2 4 + 2 b + 4 c ≥ ( 3 7 − a − b − c ) ⋅ 2 simplifying to a + 2 b + 3 c ≥ 2 5 , and we want to minimize a + b + c . Clearly we need a + b + c ≥ 9 (can also be seen by dividing it into nine 2 × 2 squares and needing one tree in each). Then you'll just need to show that at least three trees must go to edges, or at least one tree on a border and one on a corner, to show that a + b + c ≥ 1 0 . It's rather rough casework though.
@Malcolm Rich – I've realised that this way of identifying a solution is almost identical logic to Ivan's. His solution is clearly superior.
@Calvin Lin – The idea for this problem is in fact inspired from another problem where it had ( 2 n + 1 ) × ( 2 n + 1 ) . My lower bound works for any r , c for r × c (and in fact I'm pretty sure it's tight or at most off by one for all cases), but showing it is achievable is very difficult; the construction I found only worked for ( 2 n + 1 ) × ( 2 n + 1 ) . But it was easy to modify that construction to ( 2 n + 1 ) × ( 2 n + 1 + 1 ) .
i got less than yours. its 163840.so my company would get the contract lol.
Problem Loading...
Note Loading...
Set Loading...
EDIT: I just realized that the problem has been rephrased to use "trees" instead of "buildings". I haven't got any time to edit this solution, so replace "building" with "tree" in the following.
We claim that for a r × c grid, there must be at least
⌈ 3 ( r − 1 ) ( c − 1 ) + 1 ⌉
buildings. In addition, we claim that if r = 2 n + 1 , c = 2 n + 1 + 1 for some nonnegative integer n , this bound can be achieved. Since our problem is simply n = 9 , this gives the minimum number of buildings.
First, we begin by proving the bound. The idea is to count the number of lattice segments (the sides of the cells) in order to bound the number of empty cells, and thus the number of buildings.
After erecting the buildings, create a graph; the vertices are the cells that remain empty, and two vertices are adjacent exactly if their cells are orthogonally adjacent. The condition on the problem implies that the resulting graph must be a tree: it may not have any cycle (if it has a cycle, pick any two vertices on the cycle; there are two ways from one vertex to go to the other), and it must be connected (if it isn't, pick two vertices on different components; by definition, there is no path between them).
Suppose we have v vertices in our graph. Note that since we want to minimize the number of buildings, then we want to maximize the number of empty cells, so we want to maximize v . Since the graph is a tree, it has v − 1 edges.
An equally important observation is to notice the shape produced by the empty cells. Our former observation implies that there are v − 1 segments of the lattice grid that are between two adjacent empty cells.
Now, we claim by induction on v that the perimeter of the shape is 2 v + 2 .
For v = 1 , this is trivial; there's only one empty cell, so its perimeter is 4. If we have proven the claim for v = k , then consider the case v = k + 1 . This is the result of adding a new cell to a shape of k cells. The new cell must be adjacent to at least one earlier cell (otherwise it's unattached), but it cannot be adjacent to two or more cells: if it is adjacent to p , q , then since p , q both belong to the shape, there is already a path connecting them together. Adding the new cell would give p , q a second way (through the new cell), so this is not allowed. Thus the new cell is adjacent to exactly one previous cell: from the perimeter, one unit is lost (the side where the new cell sticks in), but three units is gained (the other three sides), so the perimeter increases by 2, from 2 k + 2 to 2 k + 4 . This proves the claim.
Finally, we gather all observations together. There are v − 1 segments between two adjacent empty cells. There are 2 v + 2 segments between an empty cell and a not-empty cell (whether that's a building or the outside of the grid). How many segments do we have between two not-empty cells? At least one: around the border of the grid, there must be at least one building, otherwise the border of the grid creates a cycle of empty cells. This building and the outside of the grid are two adjacent not-empty cells.
In total, we have shown that there must be at least ( v − 1 ) + ( 2 v + 2 ) + 1 = 3 v + 2 segments. But the number of segments in total is r ( c + 1 ) + ( r + 1 ) c = 2 r c + r + c . Thus we must have 2 r c + r + c ≥ 3 v + 2 , or v ≤ 3 2 r c + r + c − 2 . Since v is the number of empty cells, the number of buildings is then r c − v ≥ 3 r c − r − c + 2 = 3 ( r − 1 ) ( c − 1 ) + 1 , proving the bound.
It remains to prove that this bound is achievable, at least for the special case r = 2 n + 1 , c = 2 n + 1 + 1 (in which the bound says ⌈ 3 2 2 n + 1 + 1 ⌉ ). We prove this by induction on n .
The base case n = 0 is straightforward; put one building on the middle of bottom row. This matches the bound of 1.
Suppose we have proven the claim for n = k , and we want to prove the claim for n = k + 1 . We "blow up" the city for n = k , inserting a new row between each pair of adjacent rows, and similarly with columns. We then add a building on the intersections of the newly added rows and columns.
We will claim that this matches the bound, and it's valid.
Matching the bound is easy: we added 2 k rows and 2 k + 1 columns, so there are 2 2 k + 1 new buildings. With ⌈ 3 2 2 k + 1 + 1 ⌉ buildings previously built, we have a total of 2 k + 1 + ⌈ 3 2 2 k + 1 + 1 ⌉ = ⌈ 3 2 2 k + 3 + 1 ⌉ buildings, matching the bound.
Proving that it's valid is also pretty straightforward. Each yellow empty cell (the newly added empty cells) is adjacent to one or two empty cells (it's clear that it's adjacent to at most two empty cells, because two of its neighbors are buildings on new intersections; proving at least one empty cell can be done by induction to show that no two buildings are adjacent). Considering the graph of empty cells, note that the graph is bipartite, colored white and yellow. (Easy to prove: new rows and columns mean no two white vertices are now adjacent, and buildings on intersections mean no two yellow vertices are adjacent.) Suppose u , v are two vertices in this graph. Any path connecting them must alternate between white and yellow vertices by the graph being bipartite; furthermore, if p , q are two consecutive white vertices on this path, there is exactly one yellow vertex r that is adjacent to both p , q (indeed, there is exactly one yellow vertex between each pair of formerly adjacent white vertices). Thus we can ignore the yellow vertices on the path, since we can uniquely recover them. This gives a sequence of white vertices, which must be a path in the original city. Since the original city has only one path between u , v , there can only be one path in this new city either.
Thus we have proven that the construction is valid, proving the claim. Plugging in n = 9 to the bound gives ⌈ 3 2 1 9 + 1 ⌉ = 1 7 4 7 6 3 .