每日一练补题(19.2.6)

本文解析了Hanoi双塔问题的动态规划解法,通过计算不同圆盘数量下的移动次数,利用高精度算法求解。同时,深入探讨了守望者逃离荒岛的算法策略,采用动态规划思路,计算在特定条件下守望者能否成功逃离。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Vijos P1354 Hanoi双塔问题(动态规划,高精度) 动态规划NOIP普及组2007

题目描述
楚继光:“防御系统还真有用,修罗王的魔法炮阵的火力果然减弱了,但好像还差一点点啊?”

墨老师:“哦,是吗,那试试双塔防御体系吧。”

如图所示,给定A,B,C三根足够长的细柱,在A柱上放有2n个中间有空的能量圆盘,共有n个不同的尺寸,每个尺寸都有两个相同的圆盘,注意这两个圆盘是不加区分的,图为n=3的情形。现要将这些圆盘移到C柱上,在移动过程中可放在B柱上暂存。每次只能移动一个圆盘,每个柱子的圆盘保持上小下大的顺序。要求输出最少移动次数。

在这里插入图片描述
输入
一个正整数,表示A柱上有2n个圆盘。

输出
仅一行,包含一个正整数,为最少移动次数。

样例输入
2

样例输出
6

提示
对于100%数据,1≤n≤200。

思路:
计算n在=1,2,3,4等情况下的结果,可推得p[i]=2*p[i-1]+2;p[i-1]=将除底座圆盘以外的所有盘移至b位的次数,2=将底座圆盘移至c位的次数,p[i-1]=将除底座圆盘以外的所有盘移至c位的次数

因为n<=200,所以要用高精度求解

代码实现

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
const int N=25;
int a[N];

int main()
{
    int n;
    scanf("%d",&n);
    a[0]=2;
    for(int i=1;i<n;i++)
    {
        int c=0;
        for(int k=0;k<=20;k++)
        {
            a[k]=a[k]*2+c;
            if(k==0) a[k]+=2;
            c=a[k]/10000;
            a[k]%=10000;
        }
    }
    int l=20;
    for(;l>0;l--) if(a[l]!=0) break;
    printf("%d",a[l--]);
    for(;l>=0;l--) printf("%04d",a[l]);
    printf("\n");
    return 0;
}

守望者的逃离

题目描述

恶魔猎手尤迪安野心勃勃,他背叛了暗夜精灵,率领深藏在海底的娜迦族企图叛变。守望者在与尤迪安的交锋中遭遇了围杀,被困在一个荒芜的大岛上。为了杀死守望者,尤迪安开始对这个荒岛施咒,这座岛很快就会沉下去。到那时,岛上的所有人都会遇难。守望者的跑步速度为17m/s,以这样的速度是无法逃离荒岛的。庆幸的是守望者拥有闪烁法术,可在1s内移动60m,不过每次使用闪烁法术都会消耗魔法值10点。守望者的魔法值恢复的速度为4点/s,只有处在原地休息状态时才能恢复。

现在已知守望者的魔法初值M,他所在的初始位置与岛的出口之间的距离S,岛沉没的时间T。
你的任务写写一个程序帮助守望者计算如何在最短的时间内逃离荒岛,若不能逃出,则输出守望者在剩下的时间能走的最远距离。注意:守望者跑步、闪烁或休息活动均以秒(s)为单位,且每次活动的持续时间为整数秒。距离的单位为米(m)。

输入
输入仅一行,包括空格隔开的三个非负整数M,S,T。

输出
输出包括两行:
第1行为字符串“Yes”或“No”(区分大小写),即守望者是否能逃离荒岛。
第2行包含一个整数。第一行为“Yes”(区分大小写)时表示守望者逃离荒岛的最短时间;
第一行为“No”(区分大小写)时表示守望者能走的最远距离。

样例输入
39 200 4

样例输出
No
197

思路:
用DP的思路来解决这道问题,先计算只用传送的距离,再计算用跑步的距离,最后输出时比较两者的最大值

代码实现

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
const int N=300005;
int dpr[N],dpb[N];

int main()
{
    int m,s,t;
    scanf("%d%d%d",&m,&s,&t);
    int i=1;
    for(;i<=t;i++)
    {
        if(m>=10)
        {
            m-=10;
            dpb[i]=dpb[i-1]+60;
        }
        else
        {
            m+=4;
            dpb[i]=dpb[i-1];
        }
        dpr[i]=max(dpr[i-1]+17,dpb[i]);
        if(dpr[i]>=s) break;
    }
    if(i<=t) printf("Yes\n%d\n",i);
    else printf("No\n%d\n",dpr[t]);
    return 0;
}

### DevExpress Version 19.2.5 Overview DevExpress Universal Subscription, also known as the DXperience Universal Suite or simply referred to as the Universe Edition, represents one of the most extensively utilized .NET UI control packages globally[^3]. The specific version 19.2.5 marks an important milestone with updates that enhance its capabilities across various platforms. #### Download Information For developers seeking resources related to this particular edition, comprehensive documentation and download options are available through official channels dedicated to providing support materials for different versions including v19.2. This includes detailed guides on installation procedures which can be found within the provided help documentations specifically tailored for users looking into downloading and utilizing features introduced in version 19.2.5[^1]. #### Release Notes Highlights The release notes highlight significant improvements made in areas such as performance optimization, bug fixes, new functionalities added along with enhancements aimed at improving developer productivity when building applications using WinForms products among others[^2]. Additionally, it introduces advancements designed to facilitate better integration possibilities while ensuring compatibility across multiple environments where these tools might get deployed. ```csharp // Example C# code snippet demonstrating how to initialize a basic form application. using System; using System.Windows.Forms; namespace MyApplication { static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值