# 【Codeforces 1421 D】Hexagons，贪心，模拟

#### problem

D. Hexagons
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Lindsey Buckingham told Stevie Nicks “Go your own way”. Nicks is now sad and wants to go away as quickly as possible, but she lives in a 2D hexagonal world.

Consider a hexagonal tiling of the plane as on the picture below.

Nicks wishes to go from the cell marked (0,0) to a certain cell given by the coordinates. She may go from a hexagon to any of its six neighbors you want, but there is a cost associated with each of them. The costs depend only on the direction in which you travel. Going from (0,0) to (1,1) will take the exact same cost as going from (−2,−1) to (−1,0). The costs are given in the input in the order c1, c2, c3, c4, c5, c6 as in the picture below.

Print the smallest cost of a path from the origin which has coordinates (0,0) to the given cell.

Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). Description of the test cases follows.

The first line of each test case contains two integers x and y (−109≤x,y≤109) representing the coordinates of the target hexagon.

The second line of each test case contains six integers c1, c2, c3, c4, c5, c6 (1≤c1,c2,c3,c4,c5,c6≤109) representing the six costs of the making one step in a particular direction (refer to the picture above to see which edge is for each value).

Output
For each testcase output the smallest cost of a path from the origin to the given cell.

Example
inputCopy
2
-3 1
1 3 5 7 9 11
1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
outputCopy
18
1000000000000000000
Note
The picture below shows the solution for the first sample. The cost 18 is reached by taking c3 3 times and c2 once, amounting to 5+5+5+3=18.

#### solution

/*

+ 给出一个坐标(x,y)和六个方向每步的代价
+ 求从原点按六边形模式走到终点的最小代价。

+ 从原点出发有6个方向，可是到这6个点的最小代价=min（直线,旁边两个V），所以先更新最小代价。
+ 然后直接模拟去走就行
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;
const int mod = 998244353;
LL c;
int main(){
int T;  cin>>T;
while(T--){
LL x, y;  cin>>x>>y;
for(int i=1; i<=6; i++)cin>>c[i];
c = min(c,c+c);
c = min(c,c+c);
for(int i=2; i<=5; i++)
c[i] = min(c[i],c[i-1]+c[i+1]);
if(x>=0){
if(y>=x)cout<<c*x+c*(y-x)<<"\n";
else if(y<=0)cout<<c*x+c*abs(y)<<"\n";
else cout<<c*y+c*(x-y)<<"\n";
}else{
if(y<=x)cout<<c*abs(x)+c*(abs(y)-abs(x))<<"\n";
else if(y>=0)cout<<c*abs(x)+c*y<<"\n";
else cout<<c*abs(y)+c*(abs(x)-abs(y))<<"\n";
}
}
return 0;
}


03-04 1471
08-21 30                                                                  05-26 2703
04-16 1367
08-27 36
08-18 1362
03-27 1766
08-03 2367
08-20 1230
09-16 1609
02-13 4387
06-26 1404
03-24 803
03-19 2290
04-20 1354
05-27 1359
09-20 1743
03-03 2048
05-24 1427
06-27 2110
©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客