• 【习题 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;
    }
    
  • 相关阅读:
    Linux目录结构详解
    Linux快捷键列表
    正则表达式
    Python内置函数7
    Python内置函数6
    Python内置函数5
    什么才是java的基础知识?
    单点登录原理与简单实现
    window系统 查看端口 被哪个进程占用了
    Linux Tomcat日志查看实用命令
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8227506.html
Copyright © 2020-2023  润新知