跳到正文

题解

题解:P14917 [GESP202512 五级] 数字移动

ColumbinaHyposelenia约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年12月31日
收录
2026年4月6日
更新
2026年11月11日
篇幅
约 1 分钟
题目
P14917

版本

  1. v1当前
C++
//时间复杂度:o(n),只用了四个变量。
#include <iostream>

using namespace std;
//边输入边处理版
int main() {
    int n,t,ans=0,ti=1e6;
    cin>>n;
    while(n--) {
        cin>>t;//输入
        if(t>ans)//小于等于ans不处理
            if(ti==t)//如果配对成功
                ti=1e6;//赋初值
            else {//配对未成功
                if(ti!=1e6)//内存已有
                    if(t<ti)//将ans设为或ti
                        ans=t;
                    else
                        ans=ti,ti=t;//若设为ti,将ti刷新为t
                else
                    ti=t;//若内存为空,存储
            }
    }
    cout<<ans;
    return 0;
}
原文
存档评论1 条抓取于