题目意思很简单,给你两个串,第一个串为0,1或者?,第二个串为0,1,

每次你可以对第一个串进行三种操作,1、0变为1;2、?变为0或者1;3、交换任意两个数的位置。

现在问你能否把第一个串变为第一个串?最少的步数是多少呢 ??

其实关键抓住一点:0可以变1,1不能变0。

然后剩下的就是简单的贪心了。

#include <iostream>
#include <cstring>
#include <cstdio>
#define maxn 122
using namespace std; char s1[maxn],s2[maxn];
int n,m,l,t,z1,z2,o1,o2,ans,cas=,tep; int main()
{
scanf("%d",&t);
while (t--)
{
scanf("%s",s1+);
scanf("%s",s2+);
printf("Case %d: ",++cas);
l=strlen(s1+);
ans=o1=o2=z1=z2=;
for (int i=; s1[i]; i++)
{
if (s1[i]=='') z1++;
if (s1[i]=='') o1++;
if (s2[i]=='') z2++;
if (s2[i]=='') o2++;
}
if (z1>z2)
{
printf("-1\n");
continue;
}
for (int i=; s1[i]; i++)
{
if (s1[i]=='?')
{
if (s2[i]=='' && z1<z2)
{
s1[i]='';
z1++;
ans++;
}
}
}
for (int i=; s1[i]; i++)
{
if (s1[i]=='?')
{
if (s2[i]=='' && o1<o2)
{
s1[i]='';
o1++;
ans++;
}
}
} for (int i=; s1[i]; i++)
if (s1[i]=='?')
{
if (s2[i]=='') s1[i]='',o1++;
else s1[i]='',z1++;
ans++;
} for (int i=; s1[i]; i++)
{
if (z1<z2 && s1[i]=='' && s2[i]=='')
{
ans++;
s1[i]='';
z1++,o1--;
}
} tep=;
for (int i=; s1[i]; i++)
if (s1[i]!=s2[i]) tep++;
if (tep&)
{
printf("-1\n");
continue;
}
ans+=(tep>>);
printf("%d\n",ans);
}
return ;
}

最新文章

  1. CSS3透明属性opacity
  2. Windows 10 安装TA-Lib python库
  3. 第26天 swift reflect
  4. Codeforces Round #196 (Div. 2) B. Routine Problem
  5. 夺命雷公狗---DEDECMS----5快速入门之商城快速搭建实现快递方式和支付方式的显示
  6. 【Todo】Mybatis学习-偏理论
  7. Visual C++内存泄露检测—VLD工具使用说明[转]
  8. mvc 相关js
  9. Pentaho Data Integration Step: BD Procedure Call
  10. WCF契约之---服务契约 、数据契约、 消息契约
  11. MFC鼠标单击截获鼠标双击事件,且无法记录单击的数据的解决方案
  12. mysql 设置skip_name_resolve参数 日志 [Warning] &#39;user&#39; entry &#39;root@localhost&#39; ignored in --skip-name-resolve mode
  13. Oracle两个数据库联合查询,使用Oracle DBLink
  14. Java构造器的调用顺序
  15. python - class类 (三) 类的组合
  16. OpenCV学习笔记(一) - 边界填充、Rect函数
  17. JavaScript深入
  18. 包含min函数的栈(python)
  19. 睡眠猴子——beta阶段项目总结
  20. docker查看挂载目录命令

热门文章

  1. 20155222 2016-2017-2《Java程序设计》课程总结
  2. banwagon vps装wordpress
  3. 【SHOI2008】堵塞的交通
  4. CentOS7安装及配置vsftpd (FTP服务器)
  5. 使用 AFNetworking做过断点续传吗?
  6. 搞懂.NET Framework 历史版本(2017年)
  7. Qt-Qt5最新增加程序图标方式
  8. 【第七章】MySQL数据库备份-物理备份
  9. UVa 10071
  10. 论文笔记:Visualizing and Understanding Convolutional Networks