p2326 20分wa求助
  • 板块学术版
  • 楼主Love_Stream
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/7/29 23:01
  • 上次更新2023/11/3 06:58:58
查看原帖
p2326 20分wa求助
360611
Love_Stream楼主2023/7/29 23:01
#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;
}
2023/7/29 23:01
加载中...