题解: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 ...
随机推荐
- 使用GPU计算时,单精度float32类型和半精度float16类型运算效率的区别
最近在看资料时发现写着使用float16 半精度类型的数据计算速度要比float32的单精度类型数据计算要快,因为以前没有考虑过数据类型对计算速度的影响,只知道这个会影响最终的计算结果精度.于是,好奇 ...
- springboot整合validation统一参数检查
1.背景 实际开发中对参数进行检查,是常见 比如如下代码 /** * 参数检查测试(传统做法) * * @param dto * @return */ @GetMapping("/param ...
- 重磅预告!Apache DolphinScheduler 3.2.0 新功能“剧透”
近期,Apache DolphinScheduler 将迎来 3.2.0 版本的到来.本次发版为大版本发布,将会带来众多大家期待已久的新功能和新改进.为了让用户提前感知到新版本的变化,社区特意提前&q ...
- 零基础学习人工智能—Python—Pytorch学习(八)
前言 本文介绍卷积神经网络的上半部分. 其实,学习还是需要老师的,因为我自己写文章的时候,就会想当然,比如下面的滑动窗口,我就会想当然的认为所有人都能理解,而实际上,我们在学习的过程中之所以卡顿的点多 ...
- nftables
RHEL 8 用 ntftable 替换 iptables, 新安装的 CentOS 8.3 是这样的: [root@net182-host113 ~]# nft list tablestable i ...
- WiFi基础(三):802.11ac/ax/be 与 WiFi4、WiFi5、WiFi6、WiFi7
liwen01 2024.09.08 前言 经过二十多年的发展,WiFi 在硬件能力.软件和算法.频谱资源.市场需求.电源与能效方面都有了很大的提升.所以我们能看到从最开始只有几 M 速率的 802. ...
- BOM – Navigator SendBeacon
介绍 游览器专门做给 tracking 用的接口. 从前我们想 tracking 用户点击 anchor 是比较麻烦的. 因为 click 事件触发后, 想发 ajxax 去做 tracking re ...
- ASP.NET Core – 网站发布要做的事儿 Publish, Minification, Compression, Cache, HSTS, URL Rewrite Https & www, Close IIS Feature
前言 要发布网站需要做一些优化, 比如 cache, compression, minification 等等. 以前有写过相关的文章: Asp.net core 学习笔记 ( IIS, static ...
- 全网最适合入门的面向对象编程教程:49 Python函数方法与接口-函数与方法的区别和lamda匿名函数
全网最适合入门的面向对象编程教程:49 Python 函数方法与接口-函数与方法的区别和 lamda 匿名函数 摘要: 在 Python 中,函数和方法都是代码的基本单元,用于封装和执行特定的任务:它 ...
- 解密Prompt系列38.多Agent路由策略
常见的多智能体框架有几类,有智能体相互沟通配合一起完成任务的例如ChatDev,CAMEL等协作模式, 还有就是一个智能体负责一类任务,通过选择最合适的智能体来完成任务的路由模式,当然还有一些多智能体 ...