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;
    }
    
  • 相关阅读:
    CYPEESS USB3.0程序解读之---同步FIFO(slaveFifoSync)
    CYPEESS USB3.0程序解读之---GPIO
    USB 3.0 开发要点
    关于const声明一些东西
    __attribute__ 你知多少?
    char、signed char、unsigned char的区别总结。
    CentOS7安装配置SAMBA服务器
    linux版本FTP下载
    2021年1月29日
    2021年11月28日
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8227506.html
Copyright © 2011-2022 走看看