传送门:Problem K

https://www.cnblogs.com/violet-acmer/p/9664805.html

题意:

  给你n个数,找出满足条件的最多的数的个数。

题解:

  满足条件的数的转化为二进制最高位一定相同,否则,肯定不满足条件,此题就转换为最高位相同的二进制数最多有多少个的问题。

AC代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int n;
int res[];//(1<<31) > 1e9 void Initial()
{
scanf("%d",&n);
memset(res,,sizeof(res));
}
void Process()
{
while(n--)
{
int a;
scanf("%d",&a);
int t=;
while(a > )
{
t++;
a=a>>;//向左位移最多的次数便是当前数转化成二进制后的位数
}
res[t]++;//位数相同的数最高位都是1
}
printf("%d\n",*max_element(res+,res+));//输出最高位相同的最多的数
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
Initial();
Process();
}
return ;
}

分割线:2019.5.7

省赛倒计时4天

今天中石油的比赛拉的是去年青岛网络赛的题;

时隔一年,代码风格变了不少

AC代码:

 #include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
const int maxn=1e5+; int n;
int b[]; int main()
{
int test;
while(~scanf("%d",&test))
{
while(test--)
{
scanf("%d",&n);
mem(b,);
for(int i=;i <= n;++i)
{
int a;
scanf("%d",&a);
b[(int)log2(a)]++;
}
printf("%d\n",*max_element(b,b+));
}
}
return ;
}
05-11 21:52