题意
链接: link.
思路
贪心即可
AC代码
#include <bits/stdc++.h>
using namespace std;
string u;
string d;
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
cin >> u;
cin >> d;
u = "0" + u;
u += "0";
d = "0" + d;
int res = 0;
for (int i = 1; i <= n; i++)
{
if (d[i] == '1')
{
if (u[i - 1] == '1')
{
u[i - 1] = '0';
res++;
}
else if (u[i] == '0')
{
res++;
}
else if (u[i + 1] == '1')
{
u[i + 1] = '0';
res++;
}
}
}
cout << res << endl;
}
//system("pause");
return 0;
}