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;
    }
    
  • 相关阅读:
    python_函数_文件
    Day_2_Python_str_list_dict的使用
    Day_1_Python_循环和格式化
    influxdb2.0版本部署+自启
    格式化Java内存工具JOL输出
    卷心菜的屯币日记
    influxDB时序数据库2.0FLUX查询语法使用记录
    两种转换2021-01-01T00:00:00Z为2021-01-01 00:00:00时间格式的方式(UTC时间转为yyyy-MM-dd HH:mm:ss)
    ThreadLocal的用处
    CentOS7使用ISO镜像文件作为离线Yum源
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8227506.html
Copyright © 2011-2022 走看看