题解:AT_abc370_c [ABC370C] Word Ladder
题目传送门
luogu观看
简要题意
给两个序列 \(S\) 和 \(T\),输出的第一个数是它能改变的总个数,后面跟着的第 \(i\) 个是改变 \(i\) 个数之后,字典序最小的结果。
思路
当 \(S\) 与 \(T\) 相等的话,那就无法改变了,直接输出 \(0\)。
对于总数只要 \(T_i \ne S_i\) 那它就可以改,所以只要 \(T_i \ne S_i\) 答案就加一。
- 要让字典序最小,那我们从前面开始枚举,只要 \(T_i < S_i\) 就替换,然后输出。
- 否则如果 \(T_i > S_i\) 记录位置。等枚举完后,从后往前把记录的位置也换了。
代码
#include<bits/stdc++.h>
using namespace std;
char s[1000],t[1000],ss[1000];
int n,qw,h[100000000];
main()
{
ios::sync_with_stdio(false);
cin.tie(),cout.tie();
cin>>s>>t;
if(s==t)
{
cout<<0;
return 0;
}
n=qw=strlen(s);
for(int i=0;i<n;i++)
ss[i]=s[i];
int qq=0;
for(int i=0;i<n;i++)
{
if(s[i]==t[i])
continue;
qq++;
}
cout<<qq<<endl;
qq=0;
for(int i=0;i<n;i++)
{
if(s[i]==t[i])
continue;
if(s[i]<t[i])
{
h[++qq]=i;
continue;
}
s[i]=t[i];
cout<<s<<endl;
}
for(int i=qq;i>=1;i--)
{
int j=h[i];
s[j]=t[j];
cout<<s<<endl;
}
}
题解:AT_abc370_c [ABC370C] Word Ladder的更多相关文章
- 【题解】【字符串】【BFS】【Leetcode】Word Ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequen ...
- 126. Word Ladder II
题目: Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transfo ...
- [Leetcode Week5]Word Ladder II
Word Ladder II 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/word-ladder-ii/description/ Descripti ...
- [Leetcode Week5]Word Ladder
Word Ladder题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/word-ladder/description/ Description Give ...
- 【leetcode刷题笔记】Word Ladder II
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- [LeetCode] Word Ladder 词语阶梯
Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformatio ...
- [LeetCode] Word Ladder II 词语阶梯之二
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- LeetCode:Word Ladder I II
其他LeetCode题目欢迎访问:LeetCode结题报告索引 LeetCode:Word Ladder Given two words (start and end), and a dictiona ...
- 【leetcode】Word Ladder
Word Ladder Total Accepted: 24823 Total Submissions: 135014My Submissions Given two words (start and ...
- 【leetcode】Word Ladder II
Word Ladder II Given two words (start and end), and a dictionary, find all shortest transformation ...
随机推荐
- How to evaluate the Messi Hong Kong fraud incident?
Who is Lionel Messi? URL: https://en.wikipedia.org/wiki/Lionel_Messi As a famous football player, Me ...
- 外网的一个还不错的高性能计算教程: High Performance Computing
地址: https://info.gwdg.de/wiki/doku.php?id=wiki:hpc:start =========================================== ...
- baselines算法库common/vec_env/dummy_vec_env.py模块分析
baselines算法库设计可以和多个并行环境进行交互,也就是并行采样,实现多进程并行采样的模块为subproc_vec_env.py,与此相对的只实现单个进程下多环境交互的模块即为本文所要讲的dum ...
- JVM的本地方法栈-通俗理解
1.本地方法栈(Native Method Stacks)与虚拟机栈所发挥的作用是非常相似的, 2.其区别不过是虚拟机栈为虚拟机执行Java方法(也就是字节码)服务,而本地方法栈则是为虚拟机使用到的N ...
- Django框架创建运行最小程序过程记录
基于 python语言 Django web框架下 用pycharm创建,修改,运行 最简单程序.旨在过程 ========================================== 步骤一 ...
- USACO 2024Feb Silver
https://usaco.org/index.php?page=feb24results 话说 usaco 赛后怎么看成绩啊.为啥 submission 只有代码没有评测结果 T3 交了巨大多次才过 ...
- 使用Ollama本地离线体验SimpleRAG(手把手教程)
Ollama介绍 Ollama是一个开源项目,专注于开发和部署大语言模型,特别是像LLaMA这样的模型,用于生成高质量的文本和进行复杂的自然语言处理任务.Ollama的目标是让大语言模型的运行和使用变 ...
- Ubuntu 修改密码
强制修改密码 可以通过切换到 root 帐户强制修改密码来绕过密码长度限制: sudo su # 切换到 root 帐户 passwd USER # 修改密码 或者: sudo passwd $(wh ...
- C#自定义控件—仪表盘
C#用户控件之仪表盘 如何让温度.湿度.压力等有量程的监控值如仪表盘(DashBoard)一样显示? 思路(GDI绘图): 定义属性:(仪表盘的半径.颜色.间隙:刻度圆的半径.颜色.字体:指针的颜色. ...
- QT数据可视化框架编程实战之三维柱状图从入门到精通_补天云QT技术培训专家
QT数据可视化框架编程实战之三维柱状图从入门到精通_补天云QT技术培训专家 简介 本文将介绍QT数据可视化框架(QT DataVisualization 模块)编程实战之三维柱状图(Q3DBars)的 ...