• A Bit Fun


    A Bit Fun

    Time Limit : 5000/2500ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 43   Accepted Submission(s) : 13
    Problem Description
    There are n numbers in a array, as a[sub]0[/sub], a[sub]1[/sub] ... , a[sub]n-1[/sub], and another number m. We define a function f(i, j) = a[sub]i[/sub]|a[sub]i+1[/sub]|a[sub]i+2[/sub]| ... | a[sub]j[/sub] . Where "|" is the bit-OR operation. (i <= j) The problem is really simple: please count the number of different pairs of (i, j) where f(i, j) < m.
     
    Input
    The first line has a number T (T <= 50) , indicating the number of test cases. For each test case, first line contains two numbers n and m.(1 <= n <= 100000, 1 <= m <= 2[sup]30[/sup]) Then n numbers come in the second line which is the array a, where 1 <= a[sub]i[/sub] <= 2[sup]30[/sup].
     
    Output
    For every case, you should output "Case #t: " at first, without quotes. The [I]t[/I] is the case number starting from 1. Then follows the answer.
     
    Sample Input
    2 3 6 1 3 5 2 4 5 4
     
    Sample Output
    Case #1: 4 Case #2: 0
     
    Source
    2013 ACM/ICPC Asia Regional Chengdu Online
     
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <string.h>
     4 
     5 int main()
     6 {
     7     int T,A,B,sign;
     8     long a[100000],m,n,sum,tmp,t,i,j;
     9     scanf("%d",&T);
    10     t=1;
    11     while(T--)
    12     {
    13         sign=0;
    14         scanf("%ld%ld",&n,&m);
    15         for(i=0;i<n;i++)
    16             scanf("%ld",&a[i]);
    17         for(i=0;i<n;i++)
    18         {
    19            tmp=a[i];
    20            for(j=i;j<n;j++)
    21             {
    22                 tmp=tmp|a[j];
    23                 if(tmp<m)
    24                     sign++;
    25                 else
    26                     break;
    27             }
    28         }
    29         printf("Case #%d: %d
    ",t,sign);
    30         t++;
    31     }
    32     return 0;
    33 }
    View Code
    转载请备注:
    **************************************
    * 作者: Wurq
    * 博客: https://www.cnblogs.com/Wurq/
    * Gitee: https://gitee.com/wurq
    **************************************
  • 相关阅读:
    [C++]Linux之进程间通信小结【待完善】
    [转] thrift的使用介绍
    [转] splice系列系统调用
    [转] gdb中忽略信号处理
    [转] 确定性投资的框架
    [转] 投资策略及投资体系
    [转] 为什么医疗咨询服务公司Evolent Health仅用4年就华丽上市?
    [转] When exactly does the virtual table pointer (in C++) gets set for an object?
    [转] Linux写时拷贝技术(copy-on-write)
    [转] .bss段和.data段的区别
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750248.html
Copyright © 2020-2023  润新知