• 题意:给你两个长度为\(n\)的01串\(s\)和\(t\),可以选择\(s\)的前几位,取反然后反转,保证\(s\)总能通过不超过\(3n\)的操作得到\(t\),输出变换总数,和每次变换的位置.

  • 题解:构造题一定要充分利用题目所给的条件,对于\(s\)中的某一位i,假如它和\(t\)中的对应位置不同,我们先对前i个字符取反反转,然后再对第一个字符取反反转(就选了一个,反不反都无所谓),在取前i个位置取反反转,这样,我们就将第i个位置变换了,消耗了3次操作.这样就一定能保证在\(3n\)之内完成操作.

  • 代码:

    int t;
    int n;
    string s,tmp;
    vector<int> ans; int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>t;
    while(t--){
    cin>>n;
    cin>>s>>tmp;
    ans.clear();
    for(int i=0;i<s.size();++i){
    if(s[i]!=tmp[i]){
    ans.pb(i+1);
    ans.pb(1);
    ans.pb(i+1);
    }
    }
    cout<<ans.size()<<" ";
    for(auto w:ans){
    cout<<w<<" ";
    }
    cout<<endl;
    } return 0;
    }

Codeforces Round #658 (Div. 2) C1. Prefix Flip (Easy Version) (构造)的更多相关文章

  1. Codeforces Round #658 (Div. 2) C2. Prefix Flip (Hard Version) (构造)

    题意:给你两个长度为\(n\)的01串\(s\)和\(t\),可以选择\(s\)的前几位,取反然后反转,保证\(s\)总能通过不超过\(2n\)的操作得到\(t\),输出变换总数,和每次变换的位置. ...

  2. Codeforces Round #672 (Div. 2) C1. Pokémon Army (easy version) (DP)

    题意:给你一组数\(a\),构造一个它的子序列\(b\),然后再求\(b_1-b2+b3-b4...\),问构造后的结果最大是多少. 题解:线性DP.我们用\(dp1[i]\)来表示在\(i\)位置, ...

  3. Codeforces Round #540 (Div. 3) F1. Tree Cutting (Easy Version) 【DFS】

    任意门:http://codeforces.com/contest/1118/problem/F1 F1. Tree Cutting (Easy Version) time limit per tes ...

  4. Codeforces Round #540 (Div. 3)--1118F1 - Tree Cutting (Easy Version)

    https://codeforces.com/contest/1118/problem/F1 #include<bits/stdc++.h> using namespace std; in ...

  5. Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version)

    This problem is different from the hard version. In this version Ujan makes exactly one exchange. Yo ...

  6. Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version) 构造

    B2. Character Swap (Hard Version) This problem is different from the easy version. In this version U ...

  7. Codeforces Round #599 (Div. 2) B1. Character Swap (Easy Version) 水题

    B1. Character Swap (Easy Version) This problem is different from the hard version. In this version U ...

  8. Codeforces Round #653 (Div. 3) E1. Reading Books (easy version) (贪心,模拟)

    题意:有\(n\)本书,A和B都至少要从喜欢的书里面读\(k\)本书,如果一本书两人都喜欢的话,那么他们就可以一起读来节省时间,问最少多长时间两人都能够读完\(k\)本书. 题解:我们可以分\(3\) ...

  9. Codeforces Round #650 (Div. 3) F1. Flying Sort (Easy Version) (离散化,贪心)

    题意:有一组数,每次操作可以将某个数移到头部或者尾部,问最少操作多少次使得这组数非递减. 题解:先离散化将每个数映射为排序后所对应的位置,然后贪心,求最长连续子序列的长度,那么最少的操作次数一定为\( ...

随机推荐

  1. .NET Core部署到linux(CentOS)最全解决方案,常规篇

    本文为大家介绍使用 .NET Core部署到Linux服务器的方法,通过本文你将了解到Linux在虚拟机下的安装.Xshell,Xftp的使用方法.git在linux下的交互使用以及.net core ...

  2. Java Mybatis快速入门之基本使用

    目录 搭建环境 编写 Mybatis 核心配置文件 pom导出资源失败 测试 搭建环境 新建Maven项目 导入Maven依赖 <dependencies> <!--mysql驱动- ...

  3. 攻防世界 - Web(三)

    PHP2: 1.进入页面,进行抓包或后台扫描都没有什么发现,然后网上查一波wp,发现是关于.phps文件,进入index.phps,弹出一段代码,查看源代码, <?php if("ad ...

  4. ctfhub技能树—信息泄露—备份文件下载—bak文件

    打开靶机 查看页面信息 继续使用dirsearch进行扫描 python3 dirsearch.py -u http://challenge-d4234042e1d43e96.sandbox.ctfh ...

  5. scrapy框架基于管道的持久化存储

    scrapy框架的使用 基于管道的持久化存储的编码流程 在爬虫文件中数据解析 将解析到的数据封装到一个叫做Item类型的对象 将item类型的对象提交给管道 管道负责调用process_item的方法 ...

  6. E1.获取Elixir/Erlang版本信息

    E1.获取Elixir/Erlang版本信息 获取Elixir版本 直接在shel中打开iex (interactive shell),就可以查到具体的版本信息: iex Erlang/OTP 22 ...

  7. 用CSS制做一个三角形!

    用CSS制做一个三角形! <style> .outer { width: 0; height: 0; border-left: 10px solid transparent; border ...

  8. cisco交换机路由器静态路由配置

    一.切换模式 router>en                           //用户模式enable router#conf t                      //特权模式 ...

  9. 墓碑机制与 iOS 应用程序的生命周期

    ① 应用程序的状态 iOS 应用程序一共有 5 种状态: Not running:应用未运行 Inactive:应用运行在 foreground 但没有接收事件 Active:应用运行在 foregr ...

  10. ModuleNotFoundError 模块寻找路径

    t = os.path.dirname(os.path.dirname((os.path.dirname(os.path.abspath(__file__)))))os.path.sys.path.a ...