• HDU 6186 CS Course


    CS Course

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 338    Accepted Submission(s): 167

    Problem Description
    Little A has come to college and majored in Computer and Science.

    Today he has learned bit-operations in Algorithm Lessons, and he got a problem as homework.

    Here is the problem:

    You are giving n non-negative integers a1,a2,,an, and some queries.

    A query only contains a positive integer p, which means you
    are asked to answer the result of bit-operations (and, or, xor) of all the integers except ap.
     
    Input
    There are no more than 15 test cases.

    Each test case begins with two positive integers n and p
    in a line, indicate the number of positive integers and the number of queries.

    2n,q105

    Then n non-negative integers a1,a2,,an follows in a line, 0ai109 for each i in range[1,n].

    After that there are q positive integers p1,p2,,pqin q lines, 1pin for each i in range[1,q].
     
    Output
    For each query p, output three non-negative integers indicates the result of bit-operations(and, or, xor) of all non-negative integers except ap in a line.
     

    Sample Input

    3 3
    1 1 1
    1
    2
    3
     
    Sample Output
    1 1 0
    1 1 0
    1 1 0
    求除给定数之外剩下的数的& | 异或值
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <map>
    #include <set>
    using namespace std;
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    const int M=1134217727;
    int n,a[1000005],ans,ano,anx;
    int sans,sano,sanx,q,pos[50],x,len;
    int main()
    {
        while(scanf("%d%d",&n,&q)!=EOF)
        {
            ano=0,anx=0,ans=M;
            memset(pos,0,sizeof(pos));
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
                x=a[i];
                ans&=a[i];
                ano|=a[i];
                anx^=a[i];
                len=0;
                while(x)
                {
                    pos[len++]+=x%2;
                    x>>=1;
                }
            }
            while(q--)
            {
                scanf("%d",&x);
                sans=ans;sano=ano;sanx=anx;
                x=a[x];
                sanx^=x;
                for(int i=0;i<=30;i++)
                {
                    if(pos[i]==n-1 && !(x%2)) sans+=(1<<i);
                    if(pos[i]==1 && x%2) sano-=(1<<i);
                    x>>=1;
                }
                printf("%d %d %d
    ",sans,sano,sanx);
            }
        }
        return 0;
    }
     
  • 相关阅读:
    VUE-cli使用
    2017/04/09王晨分享课大纲
    CommonJS模块和ES6模块的区别
    css常见布局方式
    从输入 URL 到页面加载完成的过程中都发生了什么
    函数节流与防抖的实现
    JavaScript表单
    jQuery方法实现
    移动端去除横向滚动条
    请假时碰到法定假期,实际请假几天?
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7463758.html
Copyright © 2020-2023  润新知