USACO 2016 US Open Contest, Gold Problem 3. 248

这里写图片描述
http://usaco.org/index.php?page=viewproblem2&cpid=647
和2048类似的游戏,大致意思就是输入一个N,数列的长度,数列中相邻两个元素如果相同可以合并并+1,比如两个3相邻,可以合并成4,求输入数列最大能出现的数字。下面贴代码及注释

#include<iostream>
#include<vector>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
typedef struct node
{
    int t;//通过t个值合成
    int x;//值
}node;
int main()
{
    freopen("248.in", "r", stdin);
    freopen("248.out","w",stdout);
    vector<node> s[250];
    int max=0;
    int N;
    cin >> N;
    node temp;
    for (int t =0;t < N;t++)
    {
        //scanf("%d", &temp.x);
        cin >> temp.x;
        temp.t = 1;
        s[t].push_back(temp);
        int j = 1;
        while (j<=t)
        {
            if (s[t].back().x >= s[t-j].front().x && s[t].back().x <= s[t-j].back().x)//判断是否可与之前的数字合成
            {
                temp.x++;                                                               //值+1
                int qqq = s[t].back().x;                                                //寻找与之前位置容器中与s[t].back()一样的值
                temp.t += (*(s[t-j].begin()+s[t].back().x-s[t-j].front().x)).t;         //合成数相加
                s[t].push_back(temp);                               
                j = s[t].back().t;                                                      //判断合成后是否可继续合成
            }
            else break;
        }
        //for (auto x : s[t])
        //  cout << x.x << " " << x.t << "          ";
        if (max < s[t].back().x) max = s[t].back().x;
    }
    cout << max << endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值