题目链接:http://codeforces.com/contest/769/problem/D


搜索题

考虑这些数的值域较小,直接${O(2^{k})}$次方枚举每个数字二进制位上是否改变,剪枝一下最不利复杂度为${O(C_{14}^{7})}$,有${10^{4}}$中取值。

最终最不利复杂度为${O(C_{14}^{7}*(10^{4}))}$


 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 100010
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,str[maxn],c[maxn],k,v[maxn];
vector<llg>a[maxn];
llg d[maxn];
void ss1(llg wz,llg res,llg x)
{
if (wz==)
{
if (res==)
{
llg val=;
for (llg i=;i<;i++) val+=(<<i)*((str[i]+c[i])%);
a[x].push_back(val);
}
return ;
}
if (res)
{
c[wz]=;
ss1(wz+,res-,x);
}
c[wz]=;
ss1(wz+,res,x);
} void ss2(llg wz,llg res,llg x)
{
if (wz==)
{
if (res==)
{
llg val=;
for (llg i=;i<;i++) val+=(<<i)*((str[i]+c[i])%);
a[x].push_back(val);
}
return ;
}
if (res)
{
c[wz]=;
ss2(wz+,res-,x);
}
c[wz]=;
ss2(wz+,res,x);
} void change_(llg x)
{
llg cs=;
while (cs<)
{
str[cs]=x%;
x/=;
cs++;
}
} int main()
{
yyj("D");
cin>>n>>k;
for (llg i=;i<=;i++)
{
change_(i);
if (k<=) ss1(,k,i);else ss2(,-k,i);
}
for (llg i=;i<=n;i++) scanf("%lld",&v[i]),d[v[i]]++;
llg ans=;
for (llg i=;i<=n;i++)
{
llg w=a[v[i]].size(),x=v[i];
for (llg j=;j<w;j++)
if (k==) ans+=d[a[x][j]]-; else ans+=d[a[x][j]];
}
cout<<ans/;
return ;
}

Codeforces 769D k-Интересные пары чисел的更多相关文章

  1. Codeforces gym102152 K.Subarrays OR

    传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...

  2. codeforces 1133E K Balanced Teams

    题目链接:http://codeforces.com/contest/1133/problem/E 题目大意: 在n个人中找到k个队伍.每个队伍必须满足最大值减最小值不超过5.求满足条件k个队伍人数的 ...

  3. Codeforces 1133E - K Balanced Teams - [DP]

    题目链接:https://codeforces.com/contest/1133/problem/C 题意: 给出 $n$ 个数,选取其中若干个数分别组成 $k$ 组,要求每组内最大值与最小值的差值不 ...

  4. codeforces 1269E K Integers (二分+树状数组)

    链接:https://codeforces.com/contest/1269/problem/E 题意:给一个序列P1,P2,P3,P4....Pi,每次可以交换两个相邻的元素,执行最小次数的交换移动 ...

  5. codeforces 1282B2. K for the Price of One (Hard Version) (dp)

    链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以 ...

  6. Codeforces 544E K Balanced Teams (DP)

    题目: You are a coach at your local university. There are nn students under your supervision, the prog ...

  7. Codeforces Gym101502 K.Malek and Summer Semester

    K. Malek and Summer Semester   time limit per test 1.0 s memory limit per test 256 MB input standard ...

  8. Codeforces 769D

    太久没写搜索因为递归边界问题卡了很久.. 题意:定义k-interesting:如果两个数的二进制形式有k位不相同,则称之为k-interesting.给出n和k,输入n个大小在[0,10000]之间 ...

  9. Codeforces 987 K预处理BFS 3n,7n+1随机结论题/不动点逆序对 X&Y=0连边DFS求连通块数目

    A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...

随机推荐

  1. xml文件中[Invalid byte 1 of 1-byte UTF-8 sequence.]的解决方案

    问题描述: 导入项目包后发生xml文件出现错误信息:[Invalid byte 1 of 1-byte UTF-8 sequence.],如下截图所示: 解决方案: 将xml文件全部内容剪切到Note ...

  2. C调用java JNI_CreateJavaVM只能调用成功一次

    https://bbs.csdn.net/topics/392264971 再使用c语言调用java代码的时候,选择使用JNI,根据网上的提示已经能够正常跑了,int mask_name( char* ...

  3. django中模型详解-字段类型与约束条件

    这片博文来详细说明django模型的使用,涉及到django模型的创建,字段介绍,以及django模型的crud操作,以及一对一等操作. 在使用模型之前,我们首先设置数据库选项,django的默认数据 ...

  4. shell 脚本的时间差计算

    在某个时间点上增加一段时间 将时间转为时间戳,然后增加时间 [root@~]# date +%s -d '2017-05-27 12:0:0' 1495857600 [root@ ~]# new_ti ...

  5. P1384 幸运数与排列

    P1384 幸运数与排列 神奇的(逆)康托展开:求1到n的全排列中字典序第k小的排列 $k<=10^9<13!$,显然$k$最多只会影响后$13$位 前面一大串都是有序从小到大排列的,于是 ...

  6. java Condition条件变量的通俗易懂解释、基本使用及注意点

    最近在看pthread方面的书,看到条件变量一节的时候,回忆了下java中条件变量的使用方式. java中条件变量都实现了java.util.concurrent.locks.Condition接口, ...

  7. Python 使用 face_recognition 人脸识别

    Python 使用 face_recognition 人脸识别 官方说明:https://face-recognition.readthedocs.io/en/latest/readme.html 人 ...

  8. 第五章 CSS常用属性笔记

    1. span标签 突显,强调局部文字的作用. 2.字体样式 font-size: 字体大小 font-style:normal,italic(倾斜) font-weight:normal,bold( ...

  9. 01:tcp/ip基本知识

    1.1 tcp常识 1.网络七层 2.TCP三层握手 ####1.第一次握手 # 建立连接时,客户端发送SYN包到服务器,其中包含客户端的初始序号seq=x,并进入SYN_SENT状态,等待服务器确认 ...

  10. linux 安装二进制包程序一般步骤

    参考:https://blog.csdn.net/linzhiji/article/details/6774410 configure/make/make install的作用 这些都是典型的使用GN ...