题目链接:https://codeforces.com/contest/1421/problem/D
把整个地图分成六个区域,每个区域都选最近的道路,
但直路的代价可能比‘V’字道路要大,也就是说每条直路可能可以被‘V’字路代替,
于是先将每条直路的代价替换成直路和‘V’路的最小代价,再进行计算
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 100010;
int T;
ll x,y;
ll c[7];
ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }
int main(){
T = read();
while(T--){
x = read(), y = read();
for(int i=1;i<=6;++i){ c[i] = read(); }
c[1] = min(c[1], c[6] + c[2]);
c[2] = min(c[2], c[1] + c[3]);
c[3] = min(c[3], c[2] + c[4]);
c[4] = min(c[4], c[5] + c[3]);
c[5] = min(c[5], c[6] + c[4]);
c[6] = min(c[6], c[5] + c[1]);
if(x >= 0){
if(y >= x) {
printf("%lld
",1ll * x * c[1] + 1ll * (y-x) * c[2]);
} else if(y<=0) {
printf("%lld
",1ll * x * c[6] + 1ll * abs(y) * c[5]);
} else {
printf("%lld
",1ll * y * c[1] + 1ll * (x - y) * c[6]);
}
}else{
if(y <= x){
printf("%lld
",1ll * abs(x) * c[4] + 1ll * (abs(y) - abs(x)) * c[5]);
} else if(y>=0){
printf("%lld
",1ll * abs(x) * c[3] + 1ll * y * c[2]);
} else{
printf("%lld
",1ll * abs(y) * c[4] + 1ll * (abs(x) - abs(y)) * c[3]);
}
}
}
return 0;
}