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

 #include <stdio.h>
#include <stdlib.h>
#include <string.h> int main()
{
int T,A,B,sign;
long a[],m,n,sum,tmp,t,i,j;
scanf("%d",&T);
t=;
while(T--)
{
sign=;
scanf("%ld%ld",&n,&m);
for(i=;i<n;i++)
scanf("%ld",&a[i]);
for(i=;i<n;i++)
{
tmp=a[i];
for(j=i;j<n;j++)
{
tmp=tmp|a[j];
if(tmp<m)
sign++;
else
break;
}
}
printf("Case #%d: %d\n",t,sign);
t++;
}
return ;
}

随机推荐

  1. Android编程获取手机的IMEI

    手机在生产时,每部手机均有一个唯一的标识(ID),国际上采用国际移动设备身份码(IMEI, International Mobile Equipment Identity).IMEI是由15位数字组成 ...

  2. Ubuntu 14.0 升级内核到指定版本

    1.卸载现有内核sudo apt purge linux-headers-* linux-headers-*-generic linux-image-*-generic linux-image-ext ...

  3. ZUFEOJ 2395 天棋哥哥大战AlphGo

    Description3月15日,人机围棋大战巅峰对决在韩国首尔落下帷幕.五番棋的最后一局中,韩国著名棋手李世乭尽管与人工智能“AlphaGo”缠斗至官子阶段,但在双双进入读秒后最终还是投子认输,以总 ...

  4. ggplot2 theme相关设置—线条设置

    在ggplot的主题射中有一部分图需要对图中的部分线条进行设置 element_line(colour = NULL, size = NULL, linetype = NULL, lineend = ...

  5. 5、Struts2自定义拦截器

    一.拦截器相关知识 1.Struts2框架剖析 Holly版本生活案例: 影视公司(拍电影)    ActionMapper 传媒公司(包装明星) ActionMapping 明星           ...

  6. STORM在线业务实践-集群空闲CPU飙高问题排查

    源:http://daiwa.ninja/index.php/2015/07/18/storm-cpu-overload/ 2015-07-18AUTHORDAIWA STORM在线业务实践-集群空闲 ...

  7. HDU 1372 Knight Moves(BFS)

    题目链接 Problem Description A friend of you is doing research on the Traveling Knight Problem (TKP) whe ...

  8. tomcat下获取当前路径的url中含有空格解决方法

    参考博文(http://www.360doc.com/content/11/1009/17/4602013_154657565.shtml) web项目发布到Tomcat之后,如果tomcat是安装在 ...

  9. java中的字符编码方式

    1. 问题由来 面试的时候被问到了各种编码方式的区别,结果一脸懵逼,这个地方集中学习一下. 2. 几种字符编码的方式 1. ASCII码 我们知道,在计算机内部,所有的信息最终都表示为一个二进制的字符 ...

  10. LeetCode OJ 42. Trapping Rain Water

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...