AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 应用
  • 更多
    • 题解
    • 分享
    • 商店
    • 问答
    • 吐槽
  • App
  • 登录/注册

AcWing 4958. 接龙数列

作者: 作者的头像   炽热的 ,  2023-05-13 15:00:16 ,  所有人可见 ,  阅读 23


2


#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1e5 + 10;

int n;
int a[N];
int f[N], g[10];

string _to_string(int x) {
    string res = "";
    while (x) res = char(x % 10 + '0') + res, x /= 10;
    return res;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i ++ ) cin >> a[i];

    int res = 0;
    for (int i = 1; i <= n; i ++ ) {
        string t = _to_string(a[i]);
        int head = t[0] - '0', tail = t[t.size() - 1] - '0';
        f[i] = 1;
        f[i] = max(f[i], g[head] + 1);
        g[tail] = max(g[tail], f[i]);
        res = max(res, f[i]);
    }

    cout << n - res;

    return 0;
}

2 评论


用户头像
微风入我怀   1天前         踩      回复

include[HTML_REMOVED]

using namespace std;
const int N=100010;
int t,a[N],b[10],c[10],f[N],z;
int main()
{ ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>t;
for(int i=1;i<=t;i)
{ cin>>a[i];
}
for(int i=1;i<=t;i
)
{
int w=a[i]%10;
int s=0;
while(a[i])
{
s=a[i]%10;
a[i]=a[i]/10;
}
f[i]=1+c[s];

c[w]=max(c[w],f[i]);
z=max(z,f[i]);

}
cout<<t-z;

return 0;

}


用户头像
我只想摸鱼   21天前         踩      回复

大佬


你确定删除吗?

© 2018-2023 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息