2013成都网络赛 两个简单题
2ohayougozaimasudaijyoubudesu
Case #1: ohayougozaimasunanodesuCase #2: daijyoubunanodesu
Problem DescriptionThere 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.
InputThe 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.
OutputFor every case, you should output "Case #t: " at first, without quotes. The t is the case number starting from 1.
Then follows the answer.
Sample Input23 61 3 52 45 4
Sample OutputCase #1: 4Case #2: 0
Source2013 ACM/ICPC Asia Regional Chengdu Online
题目大意:题目意思很简单,只是当时真的不敢暴力啊,(10^5)^2。直接暴力写出来了。。
题目地址:A Bit Fun
AC代码:#include<iostream>#include<cstring>#include<string>#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespace std;int a[100005];int main(){ int tes,i,j; int cas=0; scanf("%d",&tes); while(tes--) { int n,m; int res=0; scanf("%d%d",&n,&m); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { int tmp=0; //0|p=p for(j=i;j<n;j++) { tmp=tmp|a[j]; if(tmp>=m) break; res++; } } printf("Case #%d: %d\n",++cas,res); } return 0;}//171MS 620K