题目链接: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. 进程表示之进程ID号

    UNIX进程总是会分配一个号码用于在其命名空间总唯一地标识它们,该号码称作进程ID号,简称PID. 1.进程ID 但每个进程除了PID外,还有其他的ID,有下列几种可能的类型: (1)处于某个线程组中 ...

  2. 1、CentOS部署Java开发环境

    一.安装jdk  jdk下载地址:http://www.Oracle.com/technetwork/java/javase/downloads/jdk-6u31-download-1501634.h ...

  3. Elasticsearch集群内的原理

        一个运行中的 Elasticsearch 实例称为一个 节点,而集群是由一个或者多个拥有相同 cluster.name 配置的节点组成, 它们共同承担数据和负载的压力.当有节点加入集群中或者从 ...

  4. Java 多线程并发编程面试笔录一览

    知识体系图: 1.线程是什么? 线程是进程中独立运行的子任务. 2.创建线程的方式 方式一:将类声明为 Thread 的子类.该子类应重写 Thread 类的 run 方法 方式二:声明实现 Runn ...

  5. 每日linux命令学习-历史指令查询(history、fc、alias)

    linux历史机制对命令行中输入的命令进行编号并依此保存,以维护命令历史.登录会话期间输入的命令保存在shell内存中,若终止命令则添加至历史文件. 1. 箭头符号方向键 使用键盘上的箭头方向键可以从 ...

  6. 关于js的日期处理

    1.日期转换(Date)方法一:String变为Date var t = "2015-03-16";var array =  t.split("-");var ...

  7. 简单的windows窗口创建实例

    #include<windows.h> #include<tchar.h> LRESULT CALLBACK WndProc(HWND hwnd,UINT umsg,WPARA ...

  8. 搭建ldap服务器及web管理服务--phpldapadmin

    系统版本:centos6 安装配置openldap: yum install openldap openldap-servers openldap-clients openldap-devel com ...

  9. kali linux web程序集简述

    Burp Suite Burp Suite是一个用于执行Web应用程序安全性测试的集成平台. 它的各种工具可以无缝地协同工作,支持整个测试过程,从应用程序攻击面的初始映射和分析,到查找和利用安全漏洞. ...

  10. Python 基础指令

    ## Python 基础指令 ```Shell $ pip install ipython== # 安装指定版本的python第三方库 $ python --version #查看版本 $ which ...