zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    UDP的坏处
    进程控制块(Process Control Block, PCB)
    分布式中一些关键概念的解释
    线程池的设计实现
    [原创] 同步、异步、阻塞、非阻塞详解
    常用场景对文件状态的影响
    echo使用说明,参数详解
    Linux下源码安装ffmpeg及ffmpeg的简单使用说明
    127.0.0.1、0.0.0.0和本机IP地址的区别和使用
    链路层的简介和MTU
  • 原文地址:https://www.cnblogs.com/52why/p/7460037.html
Copyright © 2011-2022 走看看