zoukankan      html  css  js  c++  java
  • CodeForces A or B Equals C

    A or B Equals C
    Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
     

    Description

    standard input/output
    Statements

    Rami went back from school and he had an easy homework about bitwise operations (and,or,..) The homework was like this : You have an equation : " A | B = C " ( this bar '|' means OR ) you are given the value of A and B , you need to find the value of C ?? as we said before this is an easy question for Rami to solve ,but he wonderd if the equation was like this: " A | C = B " and he is given the value of A and B , how many value of C exists ?? Rami wants your help in this hard question ... He will help you as much as he can ,so he will convert the two decimal numbers(A and B) to binary representaion ( like this: if A=6 –> A=110 ) and this what he knows about OR operation and might be helpfull with your task :

    Input

    The input consists of several test cases. The first line of the input contains a single integer T, the number of the test cases. each test case consists of 3 lines : the 1st line is the length of the binary representaion of the 2 numbers.1<=n<=100 the 2nd line is the number A in base 2 .(a string consits of 0s and 1s only ) the 3rd line is the number B in base 2 .(a string consits of 0s and 1s only )

    Output

    for each test case,you need to print the number of possible values of C that make the eqaution correct in a seperate line .(read page 2 carefully)

    Sample Input

    Input
    3
    2
    10
    11
    3
    110
    110
    4
    1110
    1011
    Output
    2
    4
    IMPOSSIBLE

    Hint

    as the answer may be very very large , you should print the answer mod 1000000007. there might be no answer for the equation also , in this case you should print "IMPOSSIBLE" (without qoutes).

    写的时候找了半天错才发现要对求的数取模.....感觉智商被掏空

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    using namespace std;
    #define INF 0x3f3f3f3f
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    
    typedef long long LL;
    
    int main()
    {
        //freopen("input.txt","r",stdin);
        int t;
        cin>>t;
        while(t--)
        {
            int n;
            char a[105],b[105];
            cin>>n;
            LL res=1;
            for(int i=1;i<=n;i++)
                cin>>a[i];
            for(int i=1;i<=n;i++)
                cin>>b[i];
    
    
            for(int i=1;i<=n;i++)
            {
                if(a[i]=='1')
                {
                    if(b[i]=='0')
                    {
                        res=0;
                        break;
                    }
                    if(b[i]=='1')
                        {
                            res*=2;
                            res=res%1000000007;
                        }
                }
            }
            if(res)
                cout<<res%1000000007<<endl;
            else
                    cout<<"IMPOSSIBLE"<<endl;
    
        }
    }
    

      

  • 相关阅读:
    一个printf(结构体指针)引发的血案
    C语言指针从底层原理到花式技巧,用图文和代码帮你讲解透彻
    利用C语言中的setjmp和longjmp,来实现异常捕获和协程
    提高代码逼格的利器:宏定义从入门到放弃
    我最喜欢的进程之间通信方式消息总线
    推荐一个阅读代码、文档的利器:屏幕贴图工具
    计算机网络基础知识总结
    vi指令总结
    LVS 负载均衡器理论基础及抓包分析
    Linux命令总结大全,包含所有linux命令
  • 原文地址:https://www.cnblogs.com/Hyouka/p/5719708.html
Copyright © 2011-2022 走看看