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;
    }
    
  • 相关阅读:
    第二章 创建rails应用程序
    System Call on Linux 2.6 for i386(1) INTRODUCTION
    splayer_directshow环境搭建
    90后要统治世界了
    在家写点东西
    转:SQL Server2005 中的数据类型总结
    原创:远程服务器返回错误: (500) 内部服务器错误
    转:关闭窗口Close()
    转:VS.net 2003 打开Web项目失败的解决方法
    js接收网页参数
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8227506.html
Copyright © 2011-2022 走看看