1421D - Hexagons (贪心)

题目

思路:将此坐标转化为直角坐标系(纵坐标,横坐标),然后将六条路径优化,上cs = min(c6, c5 + c1), 下cx = min(c3, c4 + c2), 左cz = min(c5, c4 + c6), 右cy = min(c2, c3 + c1)。因为还有右上、右下的路径,所以干脆一并优化了 cys = min(c1, cy + cs), czs = cz + cs, cyx = cy + cx, czx = min(c4, cz + cx);//cys右上 czs 左上… 然后直接计算即可,详细看代码。

Code:

#include<iostream>
#include<queue>
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;

int main()
{
    int t;cin >> t;
    while (t--)
    {
        int x, y;cin >> y >> x;
        ll c1, c2, c3, c4, c5, c6;cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
        ll cs = min(c6, c5 + c1), cx = min(c3, c4 + c2), cz = min(c5, c4 + c6), cy = min(c2, c3 + c1);//cs上  cx下 cz左 cy右
        ll cys = min(c1, cy + cs), czs = cz + cs, cyx = cy + cx, czx = min(c4, cz + cx);//cys右上 .....
        if (x >= 0 && y >= 0)
        {
            ll c = min(x, y);
            x -= c, y -= c;
            cout << c * cys + x * cy + y * cs << endl;
        }
        else if (x >= 0 && y < 0)
        {
            y = abs(y);
            ll c = min(x, y);
            x -= c, y -= c;
            cout << c * cyx + x * cy + y * cx << endl;
        }
        else if (x < 0 && y < 0)
        {
            y = abs(y);x = abs(x);
            ll c = min(x, y);
            x -= c, y -= c;
            cout << c * czx + x * cz + y * cx << endl;
        }
        else if (x < 0 && y >= 0)
        {
            y = abs(y);x = abs(x);
            ll c = min(x, y);
            x -= c, y -= c;
            cout << c * czs + x * cz + y * cs << endl;
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_Rikka_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值