zoukankan      html  css  js  c++  java
  • 【习题 8-3 UVA

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    如果1的个数第一个串比第2个串多。 那么就无解。 否则。 找几个位置去凑1 优先找'?'然后才是0的位置 剩余的全都用swap操作就好

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
      	8.whatch out the detail input require
    */
    /*
        一定在这里写完思路再敲代码!!!
    */
    #include <bits/stdc++.h>
    using namespace std;
    
    int T,num[2][2],n;
    string s1,s2;
    
    void change(){
        for (int i = 0;i < n;i++)
            if (s1[i]=='?' && s2[i]=='1'){
                s1[i] = '1';
                return;
            }
        for (int i = 0;i < n;i++)
            if (s1[i]=='0' && s2[i]=='1'){
                s1[i]= '1';
                return;
            }
        for (int i = 0;i < n;i++)
            if (s1[i]=='?'){
                s1[i] = '1';
                return;
            }
        for (int i = 0;i < n;i++)
            if (s1[i]=='0') {
                s1[i] = '1';
                return;
            }
    }
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
        cin >> T;
        int kase= 0;
        while (T--){
            memset(num,0,sizeof num);
            cin >> s1 >> s2;
            n = s1.size();
            for (int i = 0;i < n;i++)
                if (s1[i]>='0' && s1[i] <='1')
                    num[0][s1[i]-'0']++;
            for (int i = 0;i < n;i++)
                if (s2[i]>='0' && s2[i] <='1')
                    num[1][s2[i]-'0']++;
    
            if (num[0][1]>num[1][1]){
                cout <<"Case "<<++kase<<": "<< -1 << endl;
                continue;
            }
            int ans = 0;
            while (num[0][1] < num[1][1]){
                ans++;
                change();
                num[0][1]++;
            }
            for (int i = 0;i < n;i++)
                if (s1[i]=='?') s1[i] = '0',ans++;
    
            for (int i = 0;i < n;i++)
            if (s1[i]=='1' && s1[i]!=s2[i]){
                ans++;
            }
            cout <<"Case "<<++kase<<": "<< ans << endl;
        }
    	return 0;
    }
    
  • 相关阅读:
    Ruby能否成为第二个Java
    攻防实践:一次入侵兼反入侵的实例
    微型PHP木马的探讨
    破解Session cookie的方法
    ASP马免杀工具—ASP万能溶剂
    微型PHP木马的探讨
    Ubuntu 8.04公布带给我们的商机
    Root logins are not allowed 的标题操持
    若何安装vixta之一若何哄骗Nero将vixta刻录成ISO光盘
    如何安排vixta之三Installing来源劈脸安排
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8227506.html
Copyright © 2011-2022 走看看