Codeforces Round #150 (Div. 1) A
2015-04-24 20:29
337 查看
//开一个数组存入当前位置二进制位每一位的最后一个位置
//处理到第i位时,让第i位数与前面的每一位的最后一位置从大到小取或
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std ;
const int maxn = 100010 ;
const int inf = (1<<20) + 100 ;
int a[maxn] ;
int a_pos[32] ;
int b_pos[maxn] ;
int vis[inf] ;
int solve(int n ,int pos)
{
int t = 0;
for(int i = 0;i <=20 ;i++)
{
if(((n&(1<<i)) == 0)&&(a_pos[i]!=0))
b_pos[t++] = a_pos[i] ;
else if((n&(1<<i))) a_pos[i] = pos ;
}
return t ;
}
int main()
{
//freopen("input.txt" ,"r",stdin);
int n ;
while(~scanf("%d" ,&n))
{
memset(vis , 0 , sizeof(vis)) ;
memset(a_pos , 0 ,sizeof(a_pos)) ;
for(int i = 1;i <= n;i++)
{
scanf("%d" ,&a[i]) ;
int sum = solve(a[i] , i);
if(sum!=0)
sort(b_pos , b_pos+sum) ;
int t = a[i] ;vis[t] = 1;
for(int j = sum - 1;j >= 0;j--)
t|=a[b_pos[j]] , vis[t] = 1 ;
}
int ans = 0 ;
for(int i = 0;i < inf ;i++)
if(vis[i])
ans++ ;
printf("%d\n" ,ans) ;
}
return 0;
}
//处理到第i位时,让第i位数与前面的每一位的最后一位置从大到小取或
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std ;
const int maxn = 100010 ;
const int inf = (1<<20) + 100 ;
int a[maxn] ;
int a_pos[32] ;
int b_pos[maxn] ;
int vis[inf] ;
int solve(int n ,int pos)
{
int t = 0;
for(int i = 0;i <=20 ;i++)
{
if(((n&(1<<i)) == 0)&&(a_pos[i]!=0))
b_pos[t++] = a_pos[i] ;
else if((n&(1<<i))) a_pos[i] = pos ;
}
return t ;
}
int main()
{
//freopen("input.txt" ,"r",stdin);
int n ;
while(~scanf("%d" ,&n))
{
memset(vis , 0 , sizeof(vis)) ;
memset(a_pos , 0 ,sizeof(a_pos)) ;
for(int i = 1;i <= n;i++)
{
scanf("%d" ,&a[i]) ;
int sum = solve(a[i] , i);
if(sum!=0)
sort(b_pos , b_pos+sum) ;
int t = a[i] ;vis[t] = 1;
for(int j = sum - 1;j >= 0;j--)
t|=a[b_pos[j]] , vis[t] = 1 ;
}
int ans = 0 ;
for(int i = 0;i < inf ;i++)
if(vis[i])
ans++ ;
printf("%d\n" ,ans) ;
}
return 0;
}
相关文章推荐
- Codeforces Round #150 (Div. 2) B dfs
- Codeforces Round #150 (Div. 1) A. The Brand New Function
- Codeforces Round #150 (Div. 2) C 位运算+思维
- Codeforces Round #150 (Div. 2)
- Codeforces Round #150 (Div. 2) B. Undoubtedly Lucky Numbers
- Codeforces Round #150 (Div. 2)
- Codeforces Round #150 (Div. 2)
- Codeforces Round #150 (Div. 2) C. The Brand New Function
- Codeforces Round #150 (Div. 2)
- Codeforces Round #382 (Div. 1) B. Taxes
- Codeforces Round #311 (Div. 2) B. Pasha and Tea【二分】
- 【Codeforces Round 333 (Div 2)C】【最短路】The Two Routes 完全图两种双向边的最小最大距离
- Codeforces Round #Pi (Div. 2) C. Geometric Progression
- Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi (超几何分布)
- Codeforces Round #Pi (Div. 2)_D. One-Dimensional Battle Ships
- Codeforces Beta Round #65 (Div. 2)
- Codeforces Round #Pi (Div. 2)——set——Berland National Library
- 【Codeforces Round 375 (Div 2) F】【构造 贪心】st-Spanning Tree 树的特殊最小生成树使得S度不超SD,T度不超TD
- Codeforces Round #Pi (Div. 2) ——B. Berland National Library