In the year of 30XX30XX participants of some world programming championship live in a single large hotel. The hotel has nn floors. Each floor has mm sections with a single corridor connecting all of them. The sections are enumerated from 11 to mm along the corridor, and all sections with equal numbers on different floors are located exactly one above the other. Thus, the hotel can be represented as a rectangle of height nn and width mm. We can denote sections with pairs of integers (i,j)(i,j), where ii is the floor, and jj is the section number on the floor.
The guests can walk along the corridor on each floor, use stairs and elevators. Each stairs or elevator occupies all sections (1,x)(1,x), (2,x)(2,x), ……, (n,x)(n,x) for some xx between 11 and mm. All sections not occupied with stairs or elevators contain guest rooms. It takes one time unit to move between neighboring sections on the same floor or to move one floor up or down using stairs. It takes one time unit to move up to vvfloors in any direction using an elevator. You can assume you don't have to wait for an elevator, and the time needed to enter or exit an elevator is negligible.
You are to process qq queries. Each query is a question "what is the minimum time needed to go from a room in section (x1,y1)(x1,y1) to a room in section (x2,y2)(x2,y2)?"
The first line contains five integers n,m,cl,ce,vn,m,cl,ce,v (2≤n,m≤1082≤n,m≤108, 0≤cl,ce≤1050≤cl,ce≤105, 1≤cl+ce≤m−11≤cl+ce≤m−1, 1≤v≤n−11≤v≤n−1) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator, respectively.
The second line contains clcl integers l1,…,lcll1,…,lcl in increasing order (1≤li≤m1≤li≤m), denoting the positions of the stairs. If cl=0cl=0, the second line is empty.
The third line contains cece integers e1,…,ecee1,…,ece in increasing order, denoting the elevators positions in the same format. It is guaranteed that all integers lili and eiei are distinct.
The fourth line contains a single integer qq (1≤q≤1051≤q≤105) — the number of queries.
The next qq lines describe queries. Each of these lines contains four integers x1,y1,x2,y2x1,y1,x2,y2 (1≤x1,x2≤n1≤x1,x2≤n, 1≤y1,y2≤m1≤y1,y2≤m) — the coordinates of starting and finishing sections for the query. It is guaranteed that the starting and finishing sections are distinct. It is also guaranteed that these sections contain guest rooms, i. e. y1y1 and y2y2 are not among lili and eiei.
Print qq integers, one per line — the answers for the queries.
5 6 1 1 3 2 5 3 1 1 5 6 1 3 5 4 3 3 5 3
7 5 4
In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit.
In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in the section 2.
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
void solve(){
int m,n,c1,c2,v;
scanf("%d%d%d%d%d",&m,&n,&c1,&c2,&v);
for(int i=1;i<=c1;i++){
scanf("%d",&a[i]);
}
for(int i=1;i<=c2;i++){
scanf("%d",&b[i]);
}
int q;
scanf("%d",&q);
while(q--){
int ans=INT_MAX;
int x1,y1,x2,y2;
scanf("%d%d%d%d",&y1,&x1,&y2,&x2);
if(y1==y2){
printf("%d\n",abs(x1-x2));
continue;
}
int w=lower_bound(a+1,a+1+c1,x1)-a;
if(w<=c1){
ans=min(ans,abs(a[w]-x1)+abs(a[w]-x2)+abs(y1-y2));
}
if(w>1){
ans=min(ans,abs(a[w-1]-x1)+abs(a[w-1]-x2)+abs(y1-y2));
}
w=lower_bound(b+1,b+1+c2,x1)-b;
if(w<=c2){
ans=min(ans,abs(b[w]-x1)+abs(b[w]-x2)+(abs(y1-y2)+v-1)/v);
}
if(w>1){
ans=min(ans,abs(b[w-1]-x1)+abs(b[w-1]-x2)+(abs(y1-y2)+v-1)/v);
}
printf("%d\n",ans);
}
}
int main(){
solve();
return 0;
}
本文介绍了一个关于30XX年世界编程锦标赛中参赛者居住的大型酒店的路径寻找算法问题。该酒店拥有n层楼,每层楼包含m个区域,并通过走廊相连。参赛者需要在限定时间内从一个房间移动到另一个房间,利用走廊、楼梯和电梯等设施,文章探讨了如何计算最短移动时间。
529

被折叠的 条评论
为什么被折叠?



