UVA 317 Hexagon

本文探讨了一种基于六边形拼接的游戏算法,通过合理安排不同数值的六边形来实现最高得分。分析了六边形的不同组合方式及其带来的收益,并通过编程实现了最优解的计算。

分析

六边形有六条边,三个方向(自顶向下,自左上向右下,自右上向左下)。
那么现给三组数据,每组数据有三个数值,分别对应三个方向的各自可选的三个值,另要求一个六边形任一方向上的两边的值相等,所以总共可以得到33=27个互异的六边形。

现在需要你从这27个中选出19个拼成如题的形状,给定规则,如果某一方向上的值均相同,那么这个方向上的收益为该值乘以该方向上的六边形个数,综合15个收益,问总收益的最大值。

考虑尝试各个组合,这里考虑一番如何组合即如何构造最大收益。考察一个方向,对应的六边形个数为3,4,5,4,3。那么这个方向上有三个数可以摆要如何摆才能最大?

不妨设a>b>c,因为要互异,所以某一方向相同的六边形有32=9个,这里可以尝试选择,(5+4)×a+(4+3)×b+3×c是不是最大呢?考虑其他的方法,如(4+4)×a+(3+3)×b+5×c。不妨假设差异最小,即a=b+1=c+2。那么两种方法的值分别为19a-12和22a-19。因为a,b,c均为正整数,所以a≥3。那么显然22a-19>19a-12(a≥3)。

经过这样的考虑,可以发现8,6,5的组合得到的收益是最大的。那么可以确定是否只要将三组数据均采用这种组合便能获得最大收益呢?

简单的尝试一下会发现,这样会出现对边重复。也就是说只能有至多只能有一个方向采用同一组收益方案。继续考虑其他的收益方案可以发现下一组应该是7,7,5。因而可以这样尝试,(4+4,3+3,5),(4+3,3+4,5),(3+4,4+3,5),即(8,6,5)和(7,7,5)。所以可以选择三个方向中的一个尝试(8,6,5),另两方向(7,7,5)。比较三种尝试的结果即可。

代码

#include <cstdio>
#include <algorithm>
using std::sort;
int hex[3][3];

int a[3] = {5, 3+3, 4+4};
int b[3] = {5, 3+4, 3+4};

void solve()
{
    int max = 0;
    for (int k = 0; k < 3; k++) {
        int s = 0;
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                if (i == k) s += hex[i][j] * a[j];
                else        s += hex[i][j] * b[j];
        max = s > max ? s : max;
    }
    printf("%d\n\n", max);
}

int main()
{
    int n;
    scanf("%d", &n);
    for (int t = 1; t <= n; t++) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++)
                scanf("%d", &hex[i][j]);
            sort(hex[i], hex[i] + 3);
        }
        printf("Test #%d\n", t);
        solve();
    }         
    return 0;
}

题目

Description

Consider a game board consisting of 19 hexagonal fields, as shown in the figure below. We can easily distinguish three main directions in the shape of the board: from top to bottom, from top-left to bottom-right, and from top-right to bottom-left. For each of these primary directions, the board can be viewed as a series of rows, consisting of 3, 4, 5, 4, and 3 fields, respectively.

9d8e9b3acf9bf26fc84bdc494237dd19

The game board has to be completely covered using a set of hexagonal pieces. Each piece carries three numbers, one for every primary board direction. Only three different numbers are used for each direction. Every possible combination of three numbers for all three directions is assigned to a piece, leading to a set of 27 unique pieces. (The board in the above figure is still in the process of being covered.)

The score of a board is calculated as the sum of all 15 row scores (5 rows for each primary direction). The row scores are calculated as follows: if all pieces in a row carry the same number for the direction of the row, the row score is this number multiplied by the number of pieces in the row. Otherwise (the pieces carry different numbers in the row direction) the row score is zero. Note that the pieces may not be rotated. For example, the score of the leftmost row in the figure is 33=9, the score of the row to its right is 411=44.

While in the real game the pieces are chosen randomly and the set of pieces is fixed, we are interested in the highest possible score for a given set of numbers for each direction, when all pieces in a row carry the same number for the direction of the row. This means you have to choose those 19 pieces that result in the highest score.

Input

The first line of the input file contains an integer n which indicates the number of test cases. Each test case consists of three lines containing three integers each. Each of these three line contains the numbers for a single primary direction. From these numbers the set of pieces is generated.

Output

For each test case output a line containing the number of the case (Test #1, Test #2, etc.), followed by a line containing the highest possible score for the given numbers. Add a blank line after each test case.

Sample Input

1
9 4 3
8 5 2
7 6 1

Sample Output

Test #1
308

内容概要:本文系统研究了电力系统短期负荷预测问题,提出并实现了基于极限学习机(ELM)及其智能优化改进模型的预测方法。研究涵盖标准ELM、白鲸优化算法(BWO)优化ELM和鹭鹰优化算法(IBOA)优化ELM三种模型,重点通过智能优化算法对ELM的输入权重与偏置参数进行全局寻优,有效克服了传统ELM因参数随机初始化导致的不稳定性和泛化能力不足的问题。文章完整呈现了从数据预处理、特征选择、模型构建、参数优化到预测结果对比分析的全流程,利用Matlab编程实现各模型的仿真验证,显著提升了预测精度与模型鲁棒性,为电力系统调度决策提供了可靠的技术支撑。; 适合人群:具备电力系统基础知识、时间序列预测理论及Matlab编程能力的高校研究生、科研机构研究人员以及电力公司从事负荷预测、电网调度与规划工作的技术人员。; 使用场景及目标:①应用于实际电力系统短期负荷预测业务中,提升电网运行调度的精细化与智能化水平;②作为智能优化算法与神经网络融合的经典案例,服务于学术论文撰写、科研项目申报及算法性能对比研究;③应对新能源大规模接入背景下负荷波动加剧的挑战,为构建高精度、强鲁棒性的现代负荷预测体系提供解决方案。; 阅读建议:建议读者结合所提供的Matlab代码进行动手实践,深入理解ELM网络结构与优化算法的集成机制,重点对比分析不同优化策略在收敛速度、预测误差(如MAE、RMSE、MAPE)等方面的性能差异,进而掌握智能优化技术在提升预测模型性能方面的关键作用。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值