HDU4737 A Bit Fun 位运算
来源:互联网 发布:手机变魔术软件蟑螂 编辑:程序博客网 时间:2024/05/17 01:19
A Bit Fun
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2858 Accepted Submission(s): 1414
Problem Description
There are n numbers in a array, as a0, a1 ... , an-1, and another number m. We define a function f(i, j) = ai|ai+1|ai+2| ... | aj . 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.
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 <= 230) Then n numbers come in the second line which is the array a, where 1 <= ai <= 230.
For each test case, first line contains two numbers n and m.(1 <= n <= 100000, 1 <= m <= 230) Then n numbers come in the second line which is the array a, where 1 <= ai <= 230.
Output
For every case, you should output "Case #t: " at first, without quotes. The t is the case number starting from 1.
Then follows the answer.
Then follows the answer.
Sample Input
23 61 3 52 45 4
Sample Output
Case #1: 4Case #2: 0
Source
2013 ACM/ICPC Asia Regional Chengdu Online
题意:告诉n是数,求一个i到j( i<=j )的序列的或,得到的结果小于m,问这样的序列有多少
思路:每次加入一个数,若大于等于m,那么从当前序列开头开始删除数字,le指向开头数字对应的序号,i为当前序列末尾位置,开头那个数字对后面造成的影响为 i-le 。在加上最后le到n的可行序列。
#include <iostream>#include <stdio.h>#include <string>#include <cstring>#include <algorithm>using namespace std;int n,m,T;int num[33];int a[100009];int main(){ scanf("%d",&T); int ca=1; while(T--) { scanf("%d%d",&n,&m); for(int i=0; i<n; i++) { scanf("%d",&a[i]); } memset(num,0,sizeof num); int tmp=0,le=0,ans=0; for(int i=0; i<n; i++) { tmp|=a[i]; for(int j=0; j<30; j++) //加入当前位置上数的影响 if((1<<j) & a[i]) num[j]++; while(le<=i && tmp>=m) { ans+=i-le; for(int j=0; j<30; j++) if((1<<j)&a[le]) { num[j]--; if(num[j]==0) tmp^=(1<<j); } le++; } } for(int i=le;i<n;i++) //结尾还有连续可加入的部分 ans+=n-i; printf("Case #%d: %d\n",ca++,ans); } return 0;}
0 0
- HDU4737 A Bit Fun 位运算
- HDU4737--A Bit Fun HDU(149)
- HDU4737:A Bit Fun(二分)
- hdu4737 A Bit Fun (2013 网络赛 成都赛区)
- HDU 4737 A Bit Fun (位或运算)
- A Bit Fun
- A bit of fun: fun with bits
- A bit of fun: fun with bits
- HDU 4737 A Bit Fun
- hdu 4737 A Bit Fun
- Hdu 4737 A Bit Fun
- hdu 4737 A Bit Fun
- HDU-4737-A Bit Fun
- hdu 4737 A Bit Fun
- hdu 4737 A Bit Fun
- HDU 4737 A Bit Fun
- HDU 4737 A Bit Fun
- hdu 4737A Bit Fun
- 如何阅读一本书笔记之2检视阅读
- C#界面设计之树目录TreeView的使用
- 易语言学习第四课
- NYOJ 284 坦克大战
- HBase总结(十九)数据导入方式
- HDU4737 A Bit Fun 位运算
- 在VS 编译sqlite3导出dll
- TCP socket的accept/connect成功返回可是对端却不辞而别
- 并发框架SEDA
- js页面跳转常用的几种方式
- php中isset和array_key_exists测试对比
- java集合框架10——TreeMap和源码分析(一)
- uva 10806 Dijkstra, Dijkstra. dj和网络
- 委托