请问C题这样为什么只能过72%呀,求调。

#include <bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<long long>;

const int N = 1e5 + 10, INF = 1e9 + 10, mod = 1e9 + 7;

void wyx() {
	int n, x, y;
    cin >> n >> x >> y;
    string a, b, c, s;
    cin >> a >> b >> c;
    int ans = 0;
    int cnt = 0;
    vector<int> sum(4, 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)
        {
            cnt ++ ;
            if (ai == 0 && bi == 0) sum[0] ++ ;
            else if (ai == 0 && bi == 1) sum[1] ++ ;
            else if (ai == 1 && bi == 0) sum[2] ++ ;
            else if (ai == 1 && bi == 1) sum[3] ++ ;
        }
    }
    if (x * 2 <= y)
    {
        cout << x * cnt << endl;
        return;
    }
    while (1)
    {
        sort(sum.begin(), sum.end());
        ans += sum[2] * y;
        sum[3] -= sum[2];
        sum[2] -= sum[2];
        int count = 0;
        for (int i = 0; i < 4; i ++ ) if (sum[i]) count ++ ;
        if (count <= 1) break;
    }
    for (int i = 0; i < 4; i ++ ) ans += sum[i] * x;
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		wyx();
	}
	
	return 0;
}

全部评论
问题其实是在于匹配的顺序是有讲究的,例如这四种不满足的如果是3,5,7,13的话,如果处理不当,会非常又可能剩下多的就会导致错误的答案,但是如果你合理处理的话,这里的3,5,7,13是可以消除成0的,按照你的代码这里的3,5,7,13组合后是不会消除到0的,但是实际是可以的(结论是如果最小的三个数加起来大于最大的数的情况下,如果这四个加起来为奇数,最后就消除到只剩1个,否则可以全部消除掉  ,而如果加起来还小于最大数的话,那就是最大的数减去最小数后多出来的数只能用反置)
3 回复 分享
发布于 02-08 19:56 广东
赛时一直在想 3 5 4 010 101 010 为什么不能a交换前2个,b交换后2个,原来条件说了x>y,服了
2 回复 分享
发布于 02-08 18:53 江西
任意两个不同类就能凑,直接sort你可能最多的那个还有剩,而且你少的那两个也没配掉。
1 回复 分享
发布于 02-08 18:40 广东

相关推荐

怎么起名字:早知道就不读书了,害得我送外卖还得扶眼镜
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 15:58
投个小米提前批试试水,先投一个岗位看看形势,不行就再沉淀一下投第二个岗位,莫辜负
Java抽象带篮子:我嘞个骚刚,已经开始研发6g了吗
投递小米集团等公司7个岗位
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务