CF1421D.Hexagons

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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)(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)(0, 0) to (1,1)(1, 1) will take the exact same cost as going from (−2,−1)(-2, -1) to (−1,0)(-1, 0). The costs are given in the input in the order c1c_1, c2c_2, c3c_3, c4c_4, c5c_5, c6c_6 as in the picture below.

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

林赛·白金汉告诉斯蒂薇·尼克斯:“走你自己的路”(视频链接)。尼克斯现在很伤心,希望尽快离开,但她生活在一个二维六边形世界中。

考虑如下图所示的平面六边形密铺:

尼克斯希望从标有 (0,0)(0, 0) 的单元格出发,前往由坐标指定的某个目标单元格。她可以从一个六边形单元格移动到其任意一个相邻的六个单元格之一,但每次移动都有相应的代价。该代价仅取决于移动的方向。例如,从 (0,0)(0, 0) 移动到 (1,1)(1, 1) 的代价,与从 (−2,−1)(-2, -1) 移动到 (−1,0)(-1, 0) 的代价完全相同。各方向的代价在输入中按顺序给出,记为 c1c_1、c2c_2、c3c_3、c4c_4、c5c_5、c6c_6,对应关系如下面图片所示:

请输出从原点(坐标为 (0,0)(0, 0))到达给定目标单元格的最小路径代价。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^{4}). Description of the test cases follows.

The first line of each test case contains two integers xx and yy (−109≤x,y≤109-10^{9} \le x, y \le 10^{9}) representing the coordinates of the target hexagon.

The second line of each test case contains six integers c1c_1, c2c_2, c3c_3, c4c_4, c5c_5, c6c_6 (1≤c1,c2,c3,c4,c5,c6≤1091 \le c_1, c_2, c_3, c_4, c_5, c_6 \le 10^{9}) 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).

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^{4})。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 xx 和 yy(−109≤x,y≤109-10^{9} \le x, y \le 10^{9}),表示目标六边形的坐标。

每个测试用例的第二行包含六个整数 c1c_1、c2c_2、c3c_3、c4c_4、c5c_5、c6c_6(1≤c1,c2,c3,c4,c5,c6≤1091 \le c_1, c_2, c_3, c_4, c_5, c_6 \le 10^{9}),分别表示沿六个特定方向移动一步的代价(参见上方图片以确定每个值对应的边)。

输出格式

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

对于每个测试用例,输出从原点到给定单元格的路径的最小代价。

输入输出样例

  • 输入#1

    2
    -3 1
    1 3 5 7 9 11
    1000000000 1000000000
    1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

    输出#1

    18
    1000000000000000000

说明/提示

The picture below shows the solution for the first sample. The cost 1818 is reached by taking c3c_3 3 times and c2c_2 once, amounting to 5+5+5+3=185+5+5+3=18.

下图展示了第一个样例的解。花费 1818 是通过取 c3c_3 三次和 c2c_2 一次实现的,总计为 5+5+5+3=185+5+5+3=18。

输入解题思路,AI测评打分。不知道怎么写?

首页