当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4881:ZCC loves traffic lights

题目描述
ZCC loves studying,so he rarely goes home. One day he suddenly wants to go home,so he gets information about the city and calculates the minimal time to go home(He can start at any time after time 0 or exactly at time 0), if he thinks the time isn't too long, he will go home. But going home will make ZCC spend less time on study, ZCC's teacher GPS doesn't want him to go home, so GPS controls all the traffic lights and they will never become green twice(That means when a light becomes red,it will never become green). At the beginning all the lights are red.
As the end of the year is coming, in order to make the time shorter, ZCC can go through exactly one red light(Anyway, next year you will have 12 points again). But the problem becomes very hard and ZCC doesn't know how to calculate. He wants you to give him the answer.
ZCC's city is very rich, so the traffic network forms a grid graph. On each intersection point(except the 4 corners) there are traffic lights. When the red light is on, ZCC can only turn right; When the green lights is on, ZCC can go straight, turn right, turn left or turn around as he like(ZCC can only turn around on intersection points). When ZCC starts from school, he can choose any direction to go(That is, the traffic light on the starting point can't affect him).
输入解释
There are multiple test cases end with EOF(no more than 10 test cases).
The first line: two integers n,m indicating the size of ZCC's city's traffic network(2<=n,m<=20)
Next n lines each line contain m numbers, the i+1-th line's j-th number w1[i][j] indicating the first red light's end time of the point (i,j)
Next n lines each line contain m numbers, the n+i+1-th line's j-th number w2[i][j] indicating the green light's end time of the point (i,j) (1<=w1[i][j]<=w2[i][j]<=2000000)(If w1[i][j] equals to w2[i][j], it means that the light is always red. Otherwise, in [ w1[i][j]+1, w2[i][j] ] the green light is on)
(Because the corners don't have lights, you can ignore the value in the corners)
Next n lines each line contain m-1 numbers, the 2*n+i+1-th line's j-th number l1[i][j] indicating the length between point(i,j) and point(i,j+1)
Next n-1 lines each line contain m numbers, the 3*n+i+1-th line's j-th number l2[i][j] indicating the length between point(i,j) and point(i+1,j) (1<=l1[i][j],l2[i][j]<=100000)
Next line contain 4 numbers sx,sy,tx,ty indicating the school's coordinate is (sx,sy) and home's coordinate is (tx,ty).
输出解释
Multiple test cases. Each test case output the minimal time to travel. If there's no solution, output -1.
输入样例
2 2
0 0
0 0
0 0
0 0
1
2
3 5
1 1 2 2
4 3
0 1 0
1 1 1
8 1 1
0 9 0
0 1 0
1 1 1
9 1 1
0 99 0
1 1
1 1
1 1
1 1
9 4 1
1 1 1
1 1 1
1 2 4 3
输出样例
Case #1: 5
Case #2: 8

提示
[Explanation of Sample 2]
time 4:at (1,2)
time 5:at (1,3)
time 6:at (2,3)
time 7:at (2,2)
time 8:at (3,2)(7->8 run the red light)
time 9:at (3,1)
time 10:at (4,1)
time 11:at (4,2)
time 12:at (4,3)
12-4=8, so ZCC spends 8 time to go home.
来自杭电HDUOJ的附加信息
Author 镇海中学
Recommend

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-4881

最后修改于 2020-10-25T23:17:45+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 32768/32768K(Java/Others)