AtCoder ABC 251 (D ~ E)

本文介绍了AtCoder ABC 251中的两个问题,分别是D-AtMost3的构造思维题和E-Takahashi and Animals的动态规划问题。前者涉及序列构造以覆盖1到1e6的整数,后者通过状态转移设计最小成本点亮动物序列。

AtCoder ABC 251

D - At Most 3 (Contestant ver.)(构造 + 思维)

Description:

​ 构造一个长度为300的序列 任取1或者2或者3个数 使其能构成1~1e6的所有数

Solution:

​ 将1e6想办法分为三分 如果是想着/3的话 那就走上了歪路

​ 应该想的是 将六位数分割成六位 一个数可以影响两位

​ 三个数相加就可以影响6位了 于是构造方案出现

Code:

signed main()
{
    int w;
    cin >> w;
    cout << 300 << endl;
    for(int i = 1; i <= 300; i ++)
        cout << i << ' ' << i * 100 << ' ' << i * 10000 << ' ';
} 

E - Takahashi and Animals(状态DP)

Description:

​ 有一个序列 长度为n a_i代表其代价 若选择了i 那么i和**(i + 1) % n**将被点亮 并花费a_i

​ 求点亮所有位置的最小花费

Solution:

​ 很经典的一种状态设计和转移的模型

​ 我们可以简单的想到 设计**dp[i] [2]**为当前位置选和不选两种状态

​ 那么转移就可以设置为

dp[i][0] = dp[i - 1][1];
dp[i][1] = min(dp[i - 1][1], dp[i - 1][0]) + a[i];

​ 写到这里 貌似已经结束了 但其实还有问题 我们忘记考虑了点亮n和1之间的关系

​ 这点要是在转移方程里写应该会很麻烦 于是我们直接分类讨论

Code:

//一种是必选1
    f[2][1] = a[1] + a[2];
    f[2][0] = a[1];
    rep(i, 3, n + 1)
    {
        f[i][0] = f[i - 1][1];
        f[i][1] = min(f[i - 1][1], f[i - 1][0]) + a[i];
    }
    int res1 = min(f[n][1], f[n][0]);
//一种是不确定选不选1
	f[2][1] = a[2];
    f[2][0] = a[2];
    rep(i, 3, n + 2)
    {
        f[i][0] = f[i - 1][1];
        if(i == n + 1)   
            f[i][1] = min(f[i - 1][1], f[i - 1][0]) + a[1];
        else 
            f[i][1] = min(f[i - 1][1], f[i - 1][0]) + a[i];
    }
    int res2 = min(f[n + 1][1], f[n + 1][0]);
cout << min(res1, res2);
### AtCoder Contest ABC346 Problems and Information AtCoder Beginner Contest (ABC) 346 is a programming competition designed to challenge participants with various algorithmic problems. Each problem within the contest has specific constraints regarding time limits, memory usage, and expected outputs. For instance, one of the sample output formats provided shows how results should be structured when submitting solutions[^3]. The format typically includes multiple test cases where each case expects certain input parameters leading to predefined outcomes. In terms of difficulty levels, contests like these usually start from easier tasks labeled as A or B progressing towards more complex challenges marked by letters such as D or E. Participants are encouraged to solve all given questions but must adhere strictly to guidelines concerning code length restrictions not exceeding 16KB along with execution times capped at 1 second per task while ensuring that no more than 256MB RAM is utilized during processing phases. Regarding legal aspects related possibly indirectly through referencing court decisions on jurisdictional matters which might apply broadly across online platforms hosting coding competitions; however this particular citation does not directly pertain specifically here[^2]. #### Example Problem Description Consider an example problem statement similar in structure though not exact wording: Given a binary tree represented implicitly via array indices, determine whether it can be inverted so every left child becomes a right child and vice versa without altering node values themselves. This type of question would fall under graph theory concepts applied practically within competitive programming environments aimed primarily toward beginners yet still requiring solid understanding fundamental data structures including trees alongside bitwise operations potentially useful solving space-efficiently due limited resources specified earlier mentioned constraints[^1]. ```python def invert_tree(tree_arr): n = len(tree_arr) for i in range(n//2): opposite_index = ((i+1)*(-1))-1 if abs(opposite_index) <= n: temp = tree_arr[i] tree_arr[i] = tree_arr[opposite_index] tree_arr[opposite_index] = temp return tree_arr ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值