Driving in City Squares |
The city AllSquared has been designed by many famous architects and engineers.
The city
lays in a retangular area of
squared miles (n refers to the retangle
basis, and m to
its height). The streets are horizontal divisions distributed uniformly at every one
mile, and
the avenues are vertical divisions also uniformly distributed at every one mile.
Streets are
numbered from north to south, starting from zero; avenues from west to east, also
starting
from zero.
The figure (a) below portrays the city layout for n = 11 and m = 8. The city is also
#1#2#3#4#5
@font#1#2pt
#3#4#5
divided in horizontal and vertical strips, with the intersection of these strips
defining the
city subregions (counties). Figure (b) pictures a city divided into 12 counties.
Every county is associated with a vehicle circulation fee, which should be paid every time a car enters the county. If the car origin is a street or avenue delimiting the county, there is no fee. For example, in the above figure a car whose origin is street = 2 and avenue = 3 and whose target is street = 2 and avenue = 9 will have to pay only the county crossing fee relative to avenue 6.
You should write a program that has the following input:
The output should be the smallest possible price to pay for going from local 1 to local 2 .
The description for one instance has the following format:
n | m | ||
h | v | ||
s1 | s2 | ![]() |
sh-1 |
a1 | a2 | ![]() |
av-1 |
p11 | p12 | ![]() |
p1v |
p21 | p22 | ![]() |
p2v |
![]() |
|||
ph1 | ph2 | ![]() |
phv |
w1 | t1 | w2 | t2 |
% |
where
c1
c2
ck
where ci is the result for the ith instance in the input file.
100 100 3 4 30 60 10 70 80 5 100 1 20 1 100 1 20 1 1 1 20 5 5 10 75 % 11 8 4 3 1 6 7 3 6 10 10 10 10 10 10 10 10 10 10 10 10 2 3 2 9 %
6 10