社区讨论

p2326 20分wa求助

学术版参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lo21tnpy
此快照首次捕获于
2023/10/23 06:36
2 年前
此快照最后确认于
2023/11/03 06:58
2 年前
查看原帖
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n;
int a[100005];
int lg[2 * 1000005];
int cnt[25];

int read(){
	int x = 0,f = 1;
	char c = getchar();
	while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0',c = getchar();
	return x * f;
}

void write(int x){
	if(x < 0) putchar('-'),x = -x;
	if(x > 9) write(x / 10);
	putchar(x % 10 + '0'); 
}

int lowbit(int x){
	return x & -x;
}

void sum(int x,int y){
	for(;x;x -= lowbit(x)) cnt[lg[lowbit(x)]] += y;
}

bool check(int x,int y){
	for(;x;x -= lowbit(x))
		if(lg[lowbit(x)] == y)
			return true;
	return false;
}

signed main(){
	t = read();
	for(int i = 0;i <= 20;i++)
		lg[1 << i] = i;
		
	for(int k = 1;k <= t;k++){
		n = read();
		int ans = 0,maxn = 0;
		memset(cnt,0,sizeof(cnt));
		for(int i = 1;i <= n;i++){
			a[i] = read();
		}
		maxn = log(maxn) / log(2) + 1;
		for(int i = maxn;i >= 0;i--){
			if(cnt[i] <= 1)
				continue;
			ans += (1 << i);
			for(int j = 1;j <= n;j++){
				if(!a[j] & (1 << i)){
					sum(a[j],-1);
				}
			}
		}
		printf("Case #%d: ",k);
		write(ans);
		putchar('\n');
	}
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...