求站外题
  • 板块灌水区
  • 楼主OceanBrawl
  • 当前回复19
  • 已保存回复19
  • 发布时间2022/1/18 14:10
  • 上次更新2023/10/28 12:03:43
查看原帖
求站外题
567034
OceanBrawl楼主2022/1/18 14:10

rt

f(0)=0f(0)=0

f(2x)=f(x)f(2*x)=f(x)

f(2x+1)=f(x)+1f(2*x+1)=f(x)+1

nn个数aiai,统计有多少对数字函数值相同

n<=100000n<=100000,ai<=1000000000ai<=1000000000

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
ll in(){
	char c = getchar();
	int x = 0, f = 1;
	for (; c < '0' || c > '9'; c = getchar())
		if (c == '-') f = -1;
	for (; c >= '0' && c <= '9'; c = getchar())
		x = (x << 1) + (x << 3) + (c ^ 48);
	return x * f;
}

int a[100005],ans;
bool f[1000000005];
void kkk(int x)
{
    if(x<2)return ;
    if(x%2==0)
    {
        if(f[x/2])ans++;
        kkk(x/2);
    }else
    {
        if(f[x/2-1])ans++;
        kkk(x/2-1);
    }
}
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    freopen("pairs.in","r",stdin);
    freopen("pairs.out","w",stdout);
    int t;scanf("%d",&t);
    while(t--)
    {
        int n;scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            a[i]=in();f[a[i]]=1;
        }
        sort(a,a+n,cmp);
        for(int i=0;i<n;i++)
        {
            kkk(a[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

2022/1/18 14:10
加载中...