• 2017ACM/ICPC广西邀请赛 1005 CS Course


    CS Course

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


    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,,pq in 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
     
     
    题解:这道题目  要注意的是   与   或   异或  的操作    不受前后循序的影响的 
    我是使用了6个数组   保存了数组与   或   异或的前缀和   和   后缀    
     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <stdlib.h>
     4 #include <algorithm>
     5 #include <cstring>
     6 #include <math.h>
     7 using namespace std;
     8 #define MAXN 0xffffff
     9 int a[100100];
    10 int qy[100100],hy[100100];//与的前缀  后缀
    11 int qh[100100],hh[100100];//或的前缀   后缀
    12 int qyh[100100],hyh[100100];//异或的
    13 int main()
    14 {
    15     // & | ^
    16     int n,q;
    17     while(~scanf("%d%d",&n,&q))
    18     {
    19         scanf("%d",&a[1]);
    20         qy[1]=qh[1]=qyh[1]=a[1];
    21         for(int i=2; i<=n; ++i)
    22         {
    23             scanf("%d",&a[i]);
    24             qy[i]=a[i]&qy[i-1];
    25             qh[i]=a[i]|qh[i-1];
    26             qyh[i]=a[i]^qyh[i-1];
    27         }
    28         hy[n]=hh[n]=hyh[n]=a[n];
    29         //  printf("%d ",a[n]);
    30         for(int i=n-1; i>0; --i)
    31         {
    32             hy[i]=a[i]&hy[i+1];
    33             hh[i]=a[i]|hh[i+1];
    34             hyh[i]=a[i]^hyh[i+1];
    35         }
    36       /*  for(int i=1; i<=n; ++i)
    37         {
    38             printf("%d ",hh[i]);
    39         }*/
    40         while(q--)
    41         {
    42             int m;
    43             scanf("%d",&m);
    44             // printf("%d %d %d %d %d %d
    ",qy[m-1],hy[m+1],qh[m-1],hh[m+1],qyh[m-1],hyh[m+1]);
    45             if(m==1)
    46             {
    47                  printf("%d %d %d
    ",hy[m+1],hh[m+1],hyh[m+1]);
    48             }
    49             else if(m==n)
    50             {
    51                 printf("%d %d %d
    ",qy[m-1],qh[m-1],qyh[m-1]);
    52             }
    53             else
    54             {
    55                  printf("%d %d %d
    ",qy[m-1]&hy[m+1],qh[m-1]|hh[m+1],qyh[m-1]^hyh[m+1]);
    56             }
    57 
    58         }
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    数据结构_线性结构
    多线程01_基础
    操作系统05_文件管理
    解析静态内部类的使用目的与限制(转)
    mysql去除重复记录案例
    mysql 索引使用策略及优化
    mysql 索引数据结构及原理
    mysql 索引的简单使用
    当一个线程进入一个对象的一个synchronized方法后,其它线程是否可进入此对象的其它方法
    14 线程间协作的两种方式:wait、notify、notifyAll和Condition
  • 原文地址:https://www.cnblogs.com/52why/p/7460037.html
Copyright © 2020-2023  润新知