• [CF1421D] Hexagons


    [CF1421D] Hexagons

    Description

    给定一个由六边形密铺组成的坐标系中的点的坐标规律。从(0,0)出发,要到达(x,y),6种方向每种走一步都有一个费用,询问最小到达终点的费用。

    Solution

    如果让所有 a(x) 对 a(x-1) + a(x+1) 取 Min,那么最后一定能分解成不超过两段

    枚举方向,对于一个确定的方向,解方程即可

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    const int dx[6] = {1, 0, -1, -1, 0, 1};
    const int dy[6] = {1, 1, 0, -1, -1, 0};
    
    void solve()
    {
        int x, y, c[6];
        cin >> x >> y;
        for (int i = 0; i < 6; i++)
            cin >> c[i];
        for (int i = 0; i < 6; i++)
            c[(i + 1) % 6] = min(c[(i + 1) % 6], c[i] + c[(i + 2) % 6]);
        int ans = 2e18;
        for (int i = 0; i < 6; i++)
        {
            for (int j = i + 1; j < 6; j++)
            {
                if ((dx[j] * dy[i] - dx[i] * dy[j]) == 0)
                    continue;
                if ((dx[i] * dy[j] - dx[j] * dy[i]) == 0)
                    continue;
                int ai = (dx[j] * y - x * dy[j]) / (dx[j] * dy[i] - dx[i] * dy[j]);
                int aj = (dx[i] * y - x * dy[i]) / (dx[i] * dy[j] - dx[j] * dy[i]);
                if (ai >= 0 && aj >= 0)
                    ans = min(ans, ai * c[i] + aj * c[j]);
            }
        }
        cout << ans << endl;
    }
    
    signed main()
    {
        ios::sync_with_stdio(false);
    
        int t;
        cin >> t;
        while (t--)
        {
            solve();
        }
    }
    
  • 相关阅读:
    Cron表达式,springboot定时任务
    go 语言中windows Linux 交叉编译
    SSM框架处理跨域问题
    golang gin解决跨域访问
    关于Integer类的值使用==比较
    IoC注解
    spring基础知识
    SQL SERVER大话存储结构(3)_数据行的行结构
    SQL SERVER
    MySQL-记一次备份失败的排查过程
  • 原文地址:https://www.cnblogs.com/mollnn/p/14488620.html
Copyright © 2020-2023  润新知