题目描述
A civil engineer that has recently graduated from the Czech Technical University encountered an interesting problem and asked us for a help. The problem is more of economical than engineering nature. The engineer needs to connect several buildings with an infrastructure. Unfortunately, the investor is not the owner of all the land between these places. Therefore, some properties have to be bought first. The land is divided into a regular "grid" of hexagonal parcels, each of them forms an independent unit and has the same value. Some of the parcels belong to the investor. These parcels form four connected areas, each containing one building to be connected with the others. Your task is to find the minimal number of parcels that must be acquired to connect the four given areas. The whole land also has a hexagonal shape with six sides, each consisting of exactly H parcels. The above picture shows a land with H = 4 , parcels with letters represent the four areas to be connected. In this case, it is necessary to buy four additional parcels. One of the possible solutions is marked by crosses.
“话说有一天下流星雨,天上掉下来一个玉佩,它拥有无穷的力量。不过由于进入大气层的时候受到过于大的压力而导致被分成了4个部分散落在人间……”
春哥对你说了这个传说,你抱着“信春鸽,得永生”的信念来到了这块散落着的玉佩的土地上。
这是一块正六边形的土地,到达的时候你发现了它已经变成了4个部分分散在各个角落。经过探索你发现了这个玉佩只有把4块全部连到一起的时候才会发出无穷的力量,但是由于某种因素和技术原因,我们并不能移动任意一个玉佩的部分,只能通过购买一种连接用材料铺盖在土地上,把它们全部连在一起才行。
现在需要找到最少要多少钱才可以得到这无穷的力量。
比如说下图(见hint),玉佩被分成了4个部分ABCD,最少需要铺盖4块土地(用x标出)就可以把它们全部连接起来。