For #3:

Are you sure the costs aren't reversed. It should maybe be $20 through the square and $10 along the side.

The point between B and C where the pipeline joins the side, call it P.

From the drawing, this length is

The distance along the side is 100-x.

Factor in the cost:

This is what needs minimized. Therefore, differentiate, set to 0 and solve for x.