思路:
我还蛮怕这种题的。。。。
首先计算1的个数,若s多余t显然无解,之后先假设所有的问号变为t中对应字符。
再次计算st中1的个数,若不等说明问号处有问题,则问号处部分不变为1。
dif为不同数,dif += abs(s1 - t1)为总的不同处,ans = ? + dif/2。
我还蛮怕这种题的。。。。
首先计算1的个数,若s多余t显然无解,之后先假设所有的问号变为t中对应字符。
再次计算st中1的个数,若不等说明问号处有问题,则问号处部分不变为1。
dif为不同数,dif += abs(s1 - t1)为总的不同处,ans = ? + dif/2。
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype>
#include <sstream>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <algorithm>
#define SF(a) scanf("%d", &a)
#define PF(a) printf("%d\n", a)
#define SFF(a, b) scanf("%d%d", &a, &b)
#define SFFF(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SFFFF(a, b, c, d) scanf("%d%d%d%d", &a, &b, &c, &d)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define IN() freopen("in.txt", "r", stdin)
#define OUT() freopen("out.txt", "w", stdout)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (int)(a).size()
#define PB push_back
#define LL long long
#define mod 10007
#define inf 100000007
#define eps 1e-12
using namespace std;
int buf[20];
int read() {
int x = 0; char ch = getchar(); bool f = 0;
while (ch < '0' || ch > '9') { if (ch == '-') f = 1; ch = getchar(); }
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
void write(int x) {
if (!x) { putchar(48); return; }
int l = 0; if (x < 0) putchar('-'), x = -x;
while (x) buf[++l] = x % 10, x = x / 10;
while (l) putchar(buf[l--] + 48);
}
//-------------------------chc------------------------------//
int main() {
int t = read();
int kase = 1;
while (t--) {
string s, t;
cin >> s >> t;
printf("Case %d: ", kase++);
int cnt1, cnt2, ans = 0;
cnt1 = cnt2 = 0;
FOR(i, 0, SZ(s)) {
if (s[i] == '1') cnt1++;
if (t[i] == '1') cnt2++;
if (s[i] == '?') ans++;
}
if (cnt1 > cnt2) {
cout << -1 << endl;
continue;
}
int dif = 0;
cnt1 = 0;
FOR(i, 0, SZ(s)) {
if (s[i] == '?' && t[i] == '1') {
cnt1++;
}
if (s[i] == '1') cnt1++;
if (s[i] != '?' && s[i] != t[i]) dif++;
}
dif += abs(cnt1 - cnt2);
ans += dif / 2;
cout << ans << endl;
}
return 0;
}