c题题解
因为每位如果需要处理只有四种情况,而四种情况俩俩都可以通过一次交换处理完成
那么我们考虑完全不交换和尽量去交换俩种方法,如果考虑交换就尽量凑出对子
因为只要处理四组大小不是很大的数,所以我的方法是每次拿最大的和最小的一个出来凑一对
参考代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int n, x, y;
string a, b, c;
cin >> n >> x >> y;
cin >> a >> b >> c;
int t100 = 0, t111 = 0, t001 = 0, t010 = 0;
for (int i = 0; i < n; ++i) {
int ai = a[i] - '0';
int bi = b[i] - '0';
int ci = c[i] - '0';
if ((ai ^ bi) != ci) {
if(ai == 0 && bi == 0) t001++;
if(ai == 0 && bi == 1) t010++;
if(ai == 1 && bi == 0) t100++;
if(ai == 1 && bi == 1) t111++;
}
}
int prs = 0;
vector<int> t;
t.push_back(t001);t.push_back(t010);t.push_back(t100);t.push_back(t111);
while(1){
sort(t.begin(), t.end(), greater<int>() );
if(t[0] == 0) break;
while(t[(int)t.size() - 1] == 0) t.pop_back();
if(t.size() == 1) break;
t[0]--; t[(int)t.size() - 1]--;
prs++;
}
int ans1 = y * prs + x * t[0];
int ans2 = x * (t111 + t001 + t010 + t100);
int ans = min(ans1, ans2);
cout << ans;
return 0;
}
有没有更好的方法求这个对子数??