SRM 669 DIV 2 CombiningSlimes 500-point

本文探讨了在特定游戏中,玩家如何通过合并不同大小的粘液来最大化获得的吉祥物数量。通过排序和合并策略,玩家可以在每回合结束时计算出最大可能的吉祥物奖励。文章详细解释了算法实现过程,并提供了几个实例来说明最优解决方案。

Problem Statement

The idols Ami and Mami like playing games. Today they bought a new game. At the beginning of the game a group of slimes appears on the screen. In each turn of the game the player can select any two of the slimes and merge them together. The game ends when there is only one slime left.
Each slime has a positive integer size. Whenever the player merges two slimes, the size of the merged slime is x+y, where x and y are the sizes of the two merged slimes. Additionally, the player is awarded x*y mascots for performing this merge.
Ami and Mami have just started a new game. You are given a vector a containing the initial sizes of all slimes. Ami and Mami really like mascots. Find and return the maximum total number of mascots they can obtain during the game.
Definition

Class:
CombiningSlimes
Method:
maxMascots
Parameters:
vector
Returns:
int
Method signature:
int maxMascots(vector a)
(be sure your method is public)
Limits

Time limit (s):
2.000
Memory limit (MB):
256
Stack limit (MB):
256

Constraints

a will contain between 2 and 100 elements, inclusive.

Each element of a will be between 1 and 100, inclusive.
Examples
0)

{3,4}
Returns: 12
There are two slimes, their sizes are 3 and 4. There is only one possible move: we merge them into a single slime of size 7. Doing so gives us 3*4 = 12 mascots.
1)

{2,2,2}
Returns: 12
In the first turn we will merge any two slimes. The size of the new slime will be 2+2 = 4, and we will gain 2*2 = 4 mascots. In the second turn we will merge the two remaining slimes. The size of the final slime will be 4+2 = 6. The second merge will give us 4*2 = 8 mascots. Hence, the total number of mascots we will obtain is 4 + 8 = 12.
2)

{1,2,3}
Returns: 11
One optimal solution looks as follows: First, merge slimes of sizes 1 and 3. This produces a slime of size 4, and we get 3 mascots. Then, merge slimes of sizes 4 and 2. This produces a slime of size 6, and we get 8 mascots.
3)

{3,1,2}
Returns: 11
The set of slimes is the same as in Example 2, therefore the correct answer is also the same. As we can merge any two slimes, their order in a does not matter.
4)

{7,6,5,3,4,6}
Returns: 395

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

My Solution

#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <map>

using namespace std;

class CombiningSlimes
{
public:
    int maxMascots(vector <int> a);
};

int CombiningSlimes::maxMascots(vector <int> a)
{
    sort(a.begin(), a.end());
    int ans = 0;

    vector <int> temp;
    while(a.size() > 1)
    {
        int size = a.size();
        if (size % 2 != 0) a.resize(size+1, 0), size ++;

        temp.clear();
        for (int i = 0; i < size; i += 2)
        {
            temp.push_back(a[i] + a[i+1]);
            ans += a[i] * a[i+1];
        }

        a = temp;
    }

    return ans;
}
内容概要:本文围绕基于Wasserstein生成对抗网络(W-GAN)的光伏场景生成程序展开研究,提出了一种利用W-GAN生成高精度、高波动性光伏出力场景的方法,以应对新能源发电中的不确定性挑战。研究通过构建生成器与判别器之间的对抗训练机制,有效捕捉光伏出力的时间序列特征与统计分布规律,生成符合实际运行条件的多样化场景数据,弥补实测数据稀缺问题。相较于传统GAN,W-GAN引入Wasserstein距离作为损失函数,显著提升了模型训练的稳定性与梯度传播的连续性,增强了生成样本的质量与多样性。文中还提供了完整的Python代码实现,便于读者复现与拓展。; 适合人群:具备一定Python编程能力、深度学习基础的研究生、科研人员,以及从事新能源电力系统规划、优化调度、不确定性建模等相关领域的工程师和技术人员。; 使用场景及目标:①用于电力系统中可再生能源出力的不确定性建模与风险评估;②支撑微电网、综合能源系统等场景下的随机优化、鲁棒优化与分布鲁棒优化研究;③为风光互补系统、储能配置、需求响应等应用提供高质量、多样化的输入场景;④帮助研究人员掌握深度学习在能源时序数据生成中的前沿应用,推动模型迁移至风电、负荷等其他场景生成任务。; 阅读建议:建议读者结合提供的Python代码进行动手实践,深入理解W-GAN的网络架构设计、损失函数构造、训练技巧及超参数调优策略,重点关注Wasserstein距离在缓解模式崩溃与梯度消失问题中的作用,并尝试将该框架拓展至多变量、多站点或多能源联合场景生成,提升模型的泛化能力与工程实用价值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值