Variational formulas for directed polymer and percolation models on the plane