题意:

给你两个01串,经过两种操作,1.直接让第一串经过操作变成目标串;2.可以点击空白处,即0的地方,使得操作串全部清空为0串,再变为目标串;最终比较两种方式,哪种需更少步骤,输出每步点击的位置。
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 65536K,其他语言131072K
64bit IO Format: %lld

题目描述

The party began, the greasy uncle was playing cards, the fat otaku was eating, and the little beauty was drawing.

Playing cards is an indispensable and irreplaceable activity for parties. In order to be more impartial and prevent magician YHH from cheating when shuffling cards, and give full play to his mind-reading advantages at the same time, psychologist ZH proposed to use a pad to play cards.

However, ZH found that the touch screen of the pad he was assigned was malfunctioning. Every time he clicked a card, this card and all the cards behind it would be selected. As we all know, the effect of choosing a card is equivalent to changing the state of the card, that is, if the card was initially selected, it would become unselected, and if it was unselected, it would become selected. Besides, there is another operation, which is to click on the blank space, so that all the cards will become unselected.

Now ZH needs to select some cards to play, but due to the malfunctioning of the touch screen, he cannot simply choose the cards he wants to choose. Now he has used the blind trick to secretly ask netizens which positions to click to choose the cards he wants, please help him!

Given two 01-strings a and b, which represent the current state of the card and the state required by ZH. 0 represents unselected, and 1 represents selected. Now you are asked to give a plan with the smallest number of tap times.

输入描述:

There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 10), indicating the number of test cases. For each test case:

The first line contains a string a (1 ≤ |a| ≤ 10^510
5
), indicating the current state of the card.

The second line contains a string b (|b| = |a|), indicating the state required by ZH.

输出描述:

For each test case, print one line contains the minimum number of integers indicating the position ZH should tap in non-decreasing order.

Please note that number 0 is indicating the blank space, and it’s guaranteed that the solution of all the test cases is unique.

示例1

输入

2
10110
10000
110101
000000

输出

3 5
0

说明

For the first sample, a is “10110”, and b is “10000”, then ZH needs first to tap the position 3 (based on 1) to make the state become “10001”, and then tap the position 5 to make the state become “10000”, so you should tell him 3 and 5.

分析:

直接暴力遍历标记两种方式的状态,最后比较步数,直接输出即可。

AC代码

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int M=1e5+10;
int t,tot,num;
char a[M],b[M];
bool vis1[M],vis2[M];
int  main()
{scanf("%d",&t);while(t--){tot=num=0;memset(vis1,false,sizeof(vis1));memset(vis2,false,sizeof(vis2));scanf("%s%s",a+1,b+1);int l=strlen(a+1);for(int i=1; i<=l; i++){int u=b[i]-'0';if(num%2!=u){num++;vis1[i]=true;}}for(int i=1; i<=l; i++){int u=a[i]-'0';int v=b[i]-'0';if((u+tot)%2!=v){tot++;vis2[i]=true;}}if(num+1<tot){printf("0");for(int i=1; i<=l; i++)if(vis1[i])printf(" %d",i);printf("\n");}else{bool flag=false;for(int i=1; i<=l; i++)if(vis2[i]){if(!flag)printf("%d",i),flag=true;elseprintf(" %d",i);}printf("\n");}}return 0;
}

牛客网 第十七届中国计量大学程序设计竞赛(同步赛)(重现赛)B题 Broken Pad 暴力+思维相关推荐

  1. 第十七届中国计量大学程序设计竞赛 D Dessert Time

    第十七届中国计量大学程序设计竞赛 D Dessert Time 题目描述 The party began, the greasy uncle was playing cards, the fat ot ...

  2. 中国计量大学计算机编程,【题解】第三届中国计量大学程序设计竞赛(个人赛)...

    题解不是我写的,帮忙发帖~~ 第三届中国计量大学程序设计竞赛(个人赛) A.Arithmetic Problems 本题主要考察基本的编程技巧和字符串处理能力 但是从答题情况来看,虽然本题有一些陷阱, ...

  3. “华为杯”第十七届中国研究生 数学建模竞赛-【华为杯】D题:无人机集群协同对抗(附优秀论文及python代码实现)

    目录 摘 要: 1 问题重述 1.1 问题背景 1.2.1 问题一:逃逸区与最优突防策略求解

  4. “华为杯”第十七届中国研究生 数学建模竞赛-【华为杯】B题:降低汽油精制过程中的辛烷值损失模型(附优秀论文)

    目录 摘 要: 一.问题重述 二.基本假设 三.本题研究流程 四.数据处理过程与分析

  5. “华为杯”第十七届中国研究生 数学建模竞赛-【华为杯】F题:质心平衡供油策略设计:贪心和搜索的结合(附优秀论文和代码实现)

    目录 摘 要: 1.问题重述 1.1 背景介绍与问题描述 1.2 问题提出 2.模型假设 3.

  6. 华为杯数学建模2020什么时候出结果_关于组织参加“华为杯”第十七届中国研究生数学建模竞赛通知...

    亲爱的NNUers 2020年大家期待已久的 "华为杯"第十七届中国研究生数学建模竞赛 重磅来袭 遇见"华为杯" "华为杯"第十七届中国研究 ...

  7. 第十四届浙江财经大学程序设计竞赛 A A Sad Story【贪心】

    链接:https://www.nowcoder.com/acm/contest/89/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  8. 第十四届浙江财经大学程序设计竞赛重现赛 ——A

    A.  A sad story 链接:https://www.nowcoder.com/acm/contest/89/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ ...

  9. 华为社招机考考什么_牛客网-华为-2020届校园招聘上机考试-软件类机考-3

    题目描述: Apache Hadoop YARN是一种新的Hadoop资源管理器,主要部件为resource manager和node manager.resource manager使用有限状态机维 ...

最新文章

  1. 【神经网络】(8) 卷积神经网络(Mobilenet_v1),案例:cifar图像10分类
  2. Python离线安装依赖包
  3. 闭环思维之follow through和及时反馈
  4. java 页面传输中文乱码解决方式
  5. 云原生生态周报 Vol. 14 | K8s CVE 修复指南
  6. 修改Bugzilla的主页图片
  7. 方程式漏洞之复现window2008/win7 远程命令执行漏洞
  8. spring mvc学习(52):json数据类型提交
  9. redis深度历险:核心原理与应用实践_玩转Redis,阿里技术带你从核心原理到应用实践,一份文档全掌握...
  10. 顺通机器人_机器人检测
  11. matlab 按文件名排序,文件名排序Matlab程序
  12. iproxy工具的作用
  13. ERROR 999999: Error executing function. The table name is invalid. No spatial reference exists.
  14. springboot starter封装永中预览
  15. sccm可以管理linux补丁,在Linux系统中如何运用SCCM集合?
  16. 深度解析中国养老产业发展前景
  17. 问题 C: Fraction 分数类 I
  18. GPON标准简要解析
  19. Linux学习笔记—Apache
  20. 阿泡的产品管理工具包之产品经理的34个感想

热门文章

  1. C语言试题五十二之学生的记录由学号和成绩组称个,n名大学生得数据已在主函数中放入结构体数组a中,请编写函数fun,它的功能时:按分数的高低排列学生的记录,高分在前。
  2. Android之提示Cannot call this method while RecyclerView is computing a layout or scrolling
  3. C和指针之二维字符串数组用指针数组、数组指针、二级指针打印
  4. 用递归实现字符数组的反转
  5. nginx 修改配置文件使之支持pathinfo,且隐藏index.php
  6. sigmoid函数_常用的激活(激励)函数——深度学习笔记(建议收藏)
  7. 万物皆可傅里叶!用傅里叶变换还能画出世界名画!
  8. 在24小时内学完所有的数学是种什么体验?我们做了这个大胆的尝试……
  9. 大气的压力竟然能吊起相扑力士!?
  10. 物理学上最厉害的54个男人!2400年来难以超越,没想到聚在一起后这么震撼......