Codeforces Round #150 (Div. 1) A
来源:互联网 发布:windows键没反应怎么办 编辑:程序博客网 时间:2024/06/05 22:59
//开一个数组存入当前位置二进制位每一位的最后一个位置
//处理到第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;
}
0 0
- Codeforces Round #150 (Div. 1) A
- Codeforces Round #150 (Div. 1) A. The Brand New Function
- Codeforces Round #202 (Div. 1) A. Mafia
- Codeforces Round #212 (Div. 1) <A>
- Codeforces Round #215 (Div. 1) <A-B>
- Codeforces Round #232 (Div. 1) <A>
- Codeforces Round #233 (Div. 1) <A>
- Codeforces Round #239 (Div. 1)(A,B)
- Codeforces Round #253 (Div. 1)-A,B
- Codeforces Round #254 (Div. 1)-A,B
- Codeforces Round #260 (Div. 1) A. Boredom
- Codeforces Round #265 (Div. 1) A
- Codeforces Round #268 (Div. 1) A
- Codeforces Round #276 (Div. 1) A. Bits
- Codeforces Round #276 (Div. 1) A. Bits
- Codeforces Round #278 (Div. 1) A
- Codeforces Round #282 (Div. 1) A
- Codeforces Round #284 (Div. 1) A
- code::block 常用快捷键 (最常用)
- 全排列以及排列组合的输出
- noj算法设计题——踩气球
- openstack学习笔记---- filters 和 weights
- 高通 MSM8K bootloader 之一: SBL1
- Codeforces Round #150 (Div. 1) A
- 函数指针与指针函数
- 数据结构之—线性表之—顺序表
- js事件(Event)知识整理
- poj 并查集 - 大体模板
- noj算法设计题——字母转换
- 深入理解PHP之数组(遍历顺序)
- LINK : fatal error LNK1123: failure duringconversion to COFF: file invalid or corrupt
- Error Code: 1305. FUNCTION student.rand_string does not exist