Codeforces 769D k-Интересные пары чисел
题目链接: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-Интересные пары чисел的更多相关文章
- Codeforces gym102152 K.Subarrays OR
传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...
- codeforces 1133E K Balanced Teams
题目链接:http://codeforces.com/contest/1133/problem/E 题目大意: 在n个人中找到k个队伍.每个队伍必须满足最大值减最小值不超过5.求满足条件k个队伍人数的 ...
- Codeforces 1133E - K Balanced Teams - [DP]
题目链接:https://codeforces.com/contest/1133/problem/C 题意: 给出 $n$ 个数,选取其中若干个数分别组成 $k$ 组,要求每组内最大值与最小值的差值不 ...
- codeforces 1269E K Integers (二分+树状数组)
链接:https://codeforces.com/contest/1269/problem/E 题意:给一个序列P1,P2,P3,P4....Pi,每次可以交换两个相邻的元素,执行最小次数的交换移动 ...
- codeforces 1282B2. K for the Price of One (Hard Version) (dp)
链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以 ...
- Codeforces 544E K Balanced Teams (DP)
题目: You are a coach at your local university. There are nn students under your supervision, the prog ...
- 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 ...
- Codeforces 769D
太久没写搜索因为递归边界问题卡了很久.. 题意:定义k-interesting:如果两个数的二进制形式有k位不相同,则称之为k-interesting.给出n和k,输入n个大小在[0,10000]之间 ...
- 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 ...
随机推荐
- LINUX部署SVN服务器
1.安装SVN服务端 yum install -y subversion 2.创建svn版本库 mkdir -p /data/svn/myproject svnadmin create /data/s ...
- vue 实现modal
本文只是作为练习弹出框,弹框内部的东西需要进行自定义添加,主要对更新,删除,新建 ,提示四种弹框进行实现,例子中只是简单的组件应用 Modal.vue文件 <template> <d ...
- 关于Android Camera2 API 的自动对焦的坑
https://www.jianshu.com/p/280e5301b7b9 一.使用.关于Camera2的API使用,参考Google官方的例子: Camera2Basic Camera2Raw C ...
- right spindle supply short to gnd-- compact version
hardware guy found that the R1004 lead to this error, but this error should not be checked, because ...
- Pytorch-学习记录 卷积操作 cnn output_channel, etc.
参考资料: pytorch中文文档 http://pytorch-cn.readthedocs.io/zh/latest/
- php7安装redis拓展
phpredis下载地址https://github.com/phpredis/phpredis 解压并进入源码包 unzip phpredis-develop.zip cd phpredis-d ...
- py4CV例子2.5车牌识别和svm算法重构
1.什easypr数据集: ) ) ] all_label_list = temp[:, ] n_sample = , ) matcher = cv2.FlannBasedMatcher(flann ...
- Matlab绘制三维曲面(以二维高斯函数为例)
原文地址为:Matlab绘制三维曲面(以二维高斯函数为例) 寒假学习了一下Python下的NumPy和pymatlab,感觉不是很容易上手.来学校之后,决定继续看完数字图像处理一书.还是想按照上学期的 ...
- bzoj 4540 [HNOI 2016] 序列 - 莫队算法 - Sparse-Table - 单调栈
题目传送门 传送点I 传送点II 题目大意 给定一个长度为$n$的序列.询问区间$[l, r]$的所有不同的子序列的最小值的和. 这里的子序列是连续的.两个子序列不同当且仅当它们的左端点或右端点不同. ...
- Codeforces 839B Game of the Rows - 贪心
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldie ...