Hamming Distance(随机算法)
2024-08-31 04:50:56
http://acm.hdu.edu.cn/showproblem.php?pid=4712
题意:计算任意两个十六进制的数异或后1的最少个数。
思路:用随机数随机产生两个数作为下标,记录这两个数异或后1的个数,输出1的个数最少是多少。
#include <stdio.h>
#include <algorithm>
#include <time.h>
#include <math.h> using namespace std;
const int N=;
const int INF=<<;
int f[N];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,ans = INF;
scanf("%d",&n);
for (int i = ; i < n; i ++)
scanf("%x",&f[i]);
srand((unsigned)time(NULL));
for (int i = ; i < N*; i ++)
{
int a = rand()%n;
int b = rand()%n;
if (a==b)
continue ;
int t = f[a]^f[b];
int temp = __builtin_popcount(t);
ans = min(ans,temp);
}
printf("%d\n",ans);
}
return ;
}
最新文章
- Thinkphp批量添加数据
- 更加简洁易用——wangEditor富文本编辑器新版本发布
- (转)CSS 为不同大小的浏览器视窗使用不同的样式表
- JSP SQL注入--破法
- Mysql 储存过程以及 python callproc调用
- Keywords Search (ac 自己主动机)
- UpdataData
- C利用宏语言(#,##,do…while(0)盛大)
- 从头编写 asp.net core 2.0 web api 基础框架 (5) EF CRUD
- SQL Server 数据类型转换函数
- Docker Mongo数据库开启用户认证
- MySql常用命令集Mysql常用命令3
- Linux CentOS 6.9 Minimal 编译 OpenJDK 7
- Let Encrypt延期(转自虞大胆的叽叽喳喳)
- 浅谈sql中的in与not in,exists与not exists的区别以及性能分析
- 从Web Service和Remoting Service引出WCF服务
- transitionFromView方法的使用
- C#中[] 、List、Array、ArrayList等数据结构的差异简述
- PHP excel reader , excel时间转成php时间格式
- 部署jenkins问题