2018QBXT刷题游记(16)

【2018QBXT刷题游记】

Day4 TEST6

T1 subset

【题目大意】求正整数集合S最大的子集H
s.t.x,yH,xy<min(x,y)s.t. ∀x,y ∈ H,x ⊕ y<min⁡(x,y)
(T组数据)
测试数据编号 数据范围
1 – 4 1 ≤ N ≤ 16
5 – 10 1 ≤ N ≤ 1000
对于100%的数据:1ai109,T101 ≤ a_i ≤ 10^9,T≤10

【冷静分析】(这道题后面竟然没有标注今天【题目难度与顺序无关】?)
那一定……
先在草稿纸上涂涂画画,好像满足这种性质的数对不多啊??
于是找规律!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	freopen("qaq.txt","w",stdout);
	for(int i=32;i>=1;i--)
	  for(int j=32;j>=1;j--){
	if((i^j)<min(i,j))
	  cout<<i<<" "<<j<<endl;
	} 
	
	return 0;
}

8以内的是这样滴~
8 15
8 14
8 13
8 12
8 11
8 10
8 9
8 8
7 7
7 6
7 5
7 4
6 7
6 6
6 5
6 4
5 7
5 6
5 5
5 4
4 7
4 6
4 5
4 4
3 3
3 2
2 3
2 2
1 1
【滑稽】此题结束,判断二进制位数即可。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
int cnt[35],n;
ll tmp,maxn;
int qwq(ll x){
	int ret=0;
	while(x){
		ret++;
		x>>=1;
	}
	return ret;
}
int main(){
	freopen("subset.in","r",stdin);
	freopen("subset.out","w",stdout);
	while(~scanf("%d",&n)){
		maxn=0;
		memset(cnt,0,sizeof(cnt));
		for(int i=1;i<=n;i++){
		scanf("%lld",&tmp);
		cnt[qwq(tmp)]++;}
		for(int i=1;i<=34;i++)maxn=maxn>cnt[i]?maxn:cnt[i];
		printf("%lld
",maxn);
	}
	return 0;
}

开心,AC了。这次数组终于没开小!

原文地址:https://www.cnblogs.com/erutsiom/p/9905151.html